I want to alert something whenever my window get scrolled but it's not working. Here is my code
$(window).scroll(function(){
var ws = $(window).scrollTop();
if(ws)
{
alert('Scrolled');
}
});
I want to alert something whenever my window get scrolled but it's not working. Here is my code
$(window).scroll(function(){
var ws = $(window).scrollTop();
if(ws)
{
alert('Scrolled');
}
});
Share
Improve this question
edited Jun 25, 2016 at 14:07
Mohammad
21.5k16 gold badges57 silver badges85 bronze badges
asked Jun 25, 2016 at 14:06
mukul sonimukul soni
1272 silver badges7 bronze badges
2
- It work, See this – Mohammad Commented Jun 25, 2016 at 14:12
- it works just add <div style="height:1500px"></div> – Maksym Semenykhin Commented Jun 25, 2016 at 14:29
4 Answers
Reset to default 2In my case, this rule was to blame:
html,
body { overflow-x: hidden; }
Hiding overflowing elements is fine as long as the rule is applied only to the body element.
Your code works fine if you add an HTML element having height
$(window).scroll(function(){
var ws = $(window).scrollTop();
if(ws)
{
console.log(ws);
}
});
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div style="height:1500px"></div>
Try this,
CSS
body{
height:1200px;
}
Jquery
$(window).on('scroll',function(){
alert('Hi');
});
(or)
$(window).on('scroll',function(){
var wstp = $(window).scrollTop();
if(wstp)
{
alert('hi');
}
});
Just add height to your body tag and scroll.
If you want to execute or initialize function, you have to write below simple code.
$(window).on("scroll", function() {
var scrollTop = $(window).scrollTop();
if(scrollTop >= 10) {
//here is your function name
}
});
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745164027a4614536.html
评论列表(0条)