Response title
This is preview!
jQuery.expr.filters.inView = function(el) {
var width = $(el).width(),
height = $(el).height(),
offset = $(el).offset(),
vp_dimensions = {
height: $(window).height(),
width: $(window).width()
},
y_offset = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop),
x_offset = (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
return (
offset.top < (y_offset + vp_dimensions.height) && offset.left < (x_offset + vp_dimensions.width) && (offset.top + height) > y_offset && (offset.left + width) > x_offset);
};
$(window).scroll(function() {
$('li').each(function() {
var self = $(this),
title = self.find('img').attr('alt');
if (self.is(':inView')) {
$('#title').find('h2').text(title);
}
});
}).scroll();
© 2013 jQuery Foundation
Sponsored by and others.