SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Nov 2010
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    is there a way...

    to change the value of a variable whenever an image is scrolled off the screen?

    For instance, picture two large images one on top of the other. When the user scrolls down far enough that the first image is off the screen I want a certain variable to change. Is that possible?

    I looked into onblur but apparently that's just when something is currently clicked on or selected.

  2. #2
    SitePoint Evangelist
    Join Date
    Jun 2007
    Location
    North Yorkshire, UK
    Posts
    483
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have you thought of setting up a timer function that wakes up every second or so and sees whether the image is still in the viewport. ?

  3. #3
    SitePoint Member
    Join Date
    Nov 2010
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No I haven't! That sounds like it would be perfect! Do you know how to do that? It sounds difficult.

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,696
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    1 second is 1000 milliseconds, so the following should work:

    Code javascript:
    var timer = setInterval(function () {
        // do stuff here
    }, 1000);

    By assigning it to a variable, you can then, should the need require it, cancel it at some later time.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #5
    SitePoint Member
    Join Date
    Nov 2010
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry, I'm a total noob at this! How do you set it to check and see if the image is off the screen?


Bookmarks

Posting Permissions

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