How can I make an effect when mouse scrolls to a particular position?
<div id="target">
<!-- some data here -->
</div>
jQuery
var target = $('#target');
if(target.scrollTop() > 10){
alert('');
}
How can I make an effect when mouse scrolls to a particular position?
<div id="target">
<!-- some data here -->
</div>
jQuery
var target = $('#target');
if(target.scrollTop() > 10){
alert('');
}
You might have to select the entire HTML document for the scroll function, instead of just one specific div
jQuery
$(document).scroll(function(){
if ($(window).scrollTop() > 10){
// if the current scroll of the window is greater than 10px
alert('');
}
});
You need to put your code inside
$(window).on('scroll', function(){});
which will fire each time the window is scrolled like this:
$(window).on('scroll', function(){
var target = $('#target');
if(target.scrollTop() > 10){
console.log("Scrolled 10px");
alert('');
}
});