I am attempting to display a div only when certain elements with a specific class are visible in the viewport.
I made progress with this example: http://jsfiddle.net/blowsie/M2RzU/
$(document).ready(function(){
$('.myclass').bind('inview', function (event, visible) {
if (visible == true) {
// element is now visible in the viewport
$(this).removeClass('myclass');
alert('found h2!')
} else {
// element has gone out of viewport
$(this).addClass('myclass');
}
});
});
However, with this revised version: http://jsfiddle.net/deenbag/6D9x5/, the event is triggered each time any element with the class enters or exits the viewport. This means that even if one element is visible, the desired effect may be turned off if another element with the relevant class is not visible.
I also tried using this plugin but couldn't quite get it to work for my specific scenario: