Reputation: 1466
I want to do something when window scrolls to a certain position
Fiddle : https://jsfiddle.net/to1uuvnb/16/
HTML:
<div id="container"></div>
<div id="target"></div>
CSS:
#container {
min-height:300px;
max-width:400px;
background-color:#000;
}
#target {
min-height:1000px;
max-width:400px;
background-color:red;
}
JavaScript:
$('#target').scroll(function() {
if($(this).scrollTop() > 10) {
alert('');
}
});
Upvotes: 0
Views: 25
Reputation: 21779
You are attaching the scroll event to a div that has no overflow: auto;
or overflow: scroll;
set. And the question title does not seem to match with your code, I believe you want to attach the event to window
instead:
$(window).scroll(function() {
https://jsfiddle.net/to1uuvnb/17/
Upvotes: 1