admin管理员组文章数量:1294039
I have this code:
$(window).scroll(function() {
var y_scroll_pos = window.pageYOffset;
var scroll_pos_test = 200;
if(y_scroll_pos > scroll_pos_test) {
$('.extratext').slideDown('slow');
}
});
That works fine in FF, Chrome and IE 10 but not IE 9 or below. I have researched answers and they all say it should work with $(window)
instead of the usual $(document)
, which is what Ive got.
Does anyone know another way of amending this?
EDIT:
Added console.log(y_scroll_pos);
and it es up with 'undefined'. Does IE not like window.pageYOffset;
?
I have this code:
$(window).scroll(function() {
var y_scroll_pos = window.pageYOffset;
var scroll_pos_test = 200;
if(y_scroll_pos > scroll_pos_test) {
$('.extratext').slideDown('slow');
}
});
That works fine in FF, Chrome and IE 10 but not IE 9 or below. I have researched answers and they all say it should work with $(window)
instead of the usual $(document)
, which is what Ive got.
Does anyone know another way of amending this?
EDIT:
Added console.log(y_scroll_pos);
and it es up with 'undefined'. Does IE not like window.pageYOffset;
?
-
When you have html and body at height : 100%, sometime
$('html, body')
work.... Worth a try! – Karl-André Gagnon Commented Aug 27, 2013 at 4:39
1 Answer
Reset to default 7From the MDN docs:
For cross-browser patibility, use window.pageYOffset instead of window.scrollY. Additionally, older versions of Internet Explorer (< 9) do not support either property and must be worked around by checking other non-standard properties.
You could always use jQuery's implementation of scrollTop()
, it should work for all browsers:
$(window).scroll(function() {
var y_scroll_pos = $(this).scrollTop();
var scroll_pos_test = 200;
if(y_scroll_pos > scroll_pos_test) {
$('.extratext').slideDown('slow');
}
});
本文标签:
版权声明:本文标题:javascript - Jquery .scroll() not working in IE with both $(window) and $(document). (issue with window.pageYOffset?) - Stack Ov 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741596331a2387432.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论