Results 1 to 4 of 4

Thread: javascript help please

  1. #1
    Senior Member Virtual Monkey's Avatar
    Join Date
    Jan 2005
    Location
    Manchester
    Posts
    596
    Thanks
    51
    Thanked
    54 times in 32 posts
    • Virtual Monkey's system
      • Motherboard:
      • Abit IP-35E
      • CPU:
      • Intel Core 2 Duo E4600 @ stock 2.4ghz
      • Memory:
      • 3gb Corsair XMS2 DDR 6400
      • Storage:
      • 250GB Samsung HD250HJ Spinpoint
      • Graphics card(s):
      • 256MB PowerColor HD3850
      • PSU:
      • 550w Corsair VX Series PSU
      • Case:
      • Antec NSK4000 Mini Tower Case
      • Operating System:
      • Vista Home Premium
      • Monitor(s):
      • LG Flatron L226WTQ 22in

    javascript help please

    Hello all,

    I was hoping someone would be able to shed some light on what I'm doing wrong with a piece of javascript.

    I've been teaching myself html and css, and have set up a holding page for myself. I wanted to add a bit javascript which would change the background of the page as the user moves the mouse. So, as the cursor moves from top to bottom, the background colour smoothly fades from one hue to another.

    At the moment I have this from playing around with a jfiddle I found:

    Code:
    var $win = $(window),
        w = 0,h = 0,
        rgb = [],
        getWidth = function() {
            w = $win.width();
            h = $win.height();
        };
    
    $win.resize(getWidth).mousemove(function(e) {
    
        rgb = [
            Math.round(e.pageX/w * 255),
            Math.round(e.pageY/h * 255),
            150
        ];
    
        $(document.body).css('background','rgb('+rgb.join(',')+')');
    
    }).resize();
    However, I'm not sure how to put it in the html page correctly, at the moment it's in the document <body>.

    Do I need to do anything in the <style> section to specify that I want the javascript to decide the background colour?

    I hope that makes sense. Thanks for your help!

  2. #2
    Not a good person scaryjim's Avatar
    Join Date
    Jan 2009
    Location
    Gateshead
    Posts
    15,196
    Thanks
    1,230
    Thanked
    2,291 times in 1,874 posts
    • scaryjim's system
      • Motherboard:
      • Dell Inspiron
      • CPU:
      • Core i5 8250U
      • Memory:
      • 2x 4GB DDR4 2666
      • Storage:
      • 128GB M.2 SSD + 1TB HDD
      • Graphics card(s):
      • Radeon R5 230
      • PSU:
      • Battery/Dell brick
      • Case:
      • Dell Inspiron 5570
      • Operating System:
      • Windows 10
      • Monitor(s):
      • 15" 1080p laptop panel

    Re: javascript help please

    Hiya VM,

    Looks like an interesting bit of functionality you're working on. The script you've included looks like it uses jquery, so I think you'll need to include that in your page to make it work? Is this for a personal project or a professional one? I'm Mancy-based too, so if you fancy getting together to some time to bash ideas around I could be up for that (as long as it includes beer or wine ).

    I have to admit don't know much jquery, so other people may be able to drop in and offer immediate online responses, but the offer of discussing over beer/wine remains

  3. #3
    Seething Cauldron of Hatred TheAnimus's Avatar
    Join Date
    Aug 2005
    Posts
    17,164
    Thanks
    803
    Thanked
    2,152 times in 1,408 posts

    Re: javascript help please

    Sure looks like JQuery, I was going to offer help but Jim's on the case.

    The only reason I was going to help was due to the Calvin avatar FYI.
    throw new ArgumentException (String, String, Exception)

  4. #4
    Senior Member Virtual Monkey's Avatar
    Join Date
    Jan 2005
    Location
    Manchester
    Posts
    596
    Thanks
    51
    Thanked
    54 times in 32 posts
    • Virtual Monkey's system
      • Motherboard:
      • Abit IP-35E
      • CPU:
      • Intel Core 2 Duo E4600 @ stock 2.4ghz
      • Memory:
      • 3gb Corsair XMS2 DDR 6400
      • Storage:
      • 250GB Samsung HD250HJ Spinpoint
      • Graphics card(s):
      • 256MB PowerColor HD3850
      • PSU:
      • 550w Corsair VX Series PSU
      • Case:
      • Antec NSK4000 Mini Tower Case
      • Operating System:
      • Vista Home Premium
      • Monitor(s):
      • LG Flatron L226WTQ 22in

    Re: javascript help please

    Quote Originally Posted by scaryjim View Post
    Hiya VM,

    Looks like an interesting bit of functionality you're working on. The script you've included looks like it uses jquery, so I think you'll need to include that in your page to make it work? Is this for a personal project or a professional one? I'm Mancy-based too, so if you fancy getting together to some time to bash ideas around I could be up for that (as long as it includes beer or wine ).

    I have to admit don't know much jquery, so other people may be able to drop in and offer immediate online responses, but the offer of discussing over beer/wine remains
    Thanks for this, I will investigate further. It's a personal project. I just wanted to add something interesting to my holding page, and thought it would be a good excuse to play around with some coding.

    I'm actually studying in London at the moment, but I do pop back home periodically, so I will message you when I'm back over Christmas and perhaps we can talk over a drink. It's always good to meet other techy people!

    I'll do a bit more playing and post my results here.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •