Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
1
rated 0 times [  6] [ 5]  / answers: 1 / hits: 28251  / 12 Years ago, wed, september 19, 2012, 12:00:00

Please see this:



http://jsfiddle.net/5Zs6F/2/



As you can see only when you scroll past the first red rectangle it turns blue, I would like it to turn blue the moment it enters into view. This is why the second never turns blue because there isn't enough content underneath it to allow you to scroll past it.



HTML:



Scoll this window pane
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<div class=box></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<div class=box></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />


CSS:



.box { width: 250px; height: 100px; border: 2px solid red;  }


jQuery:



$.getScript('http://imakewebthings.com/jquery-waypoints/waypoints.min.js', function() {


$('.box').waypoint(function() {

$(this).css({
borderColor: 'blue'
});

});


});


How to make it fire as soon as the element in question is seen and not scrolled past?


More From » jquery

 Answers
48

The offset option determines where in relation to the top of the viewport the waypoint should fire. By default it is 0, so your element fires when it hits the top. Because what you want is common, waypoints includes a simple alias for setting the offset to fire when the whole element comes into view.



$('.box').waypoint(function() {
$(this).css({
borderColor: 'blue'
});
}, { offset: 'bottom-in-view' });


If you want it to fire when any part of the element peeks in from the bottom, you should set it to '100%'.


[#83013] Monday, September 17, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
darennevina

Total Points: 422
Total Questions: 128
Total Answers: 105

Location: Comoros
Member since Tue, Mar 14, 2023
1 Year ago
;