Safari and $(window).on('scroll')
Safari and $(window).on('scroll')
似乎在Safari(版本:9.1)中,jQuery和普通JavaScript都无法捕获滚动事件。
我的目标是捕捉滚动位置,如果它低于50px,通过添加一个类来固定导航栏,否则删除该类。
我在下面放置的代码片段在Chrome, Firefox和IE中工作,但在Safari中不工作。
$(window).on('scroll', function(){
if( $(window).scrollTop()>50 ){
$('.navbar').addClass('nav-fixed');
}
else {
$('.navbar').removeClass('nav-fixed');
}
});
我在Safari v. 10.0.1中遇到了同样的问题。
window.addEventListener('scroll',function() {
// Nothing happens here in Safari. Scroll event is never fired.
});
编辑:我有一个问题,我的CSS解决了这个问题。我有一些旧的滚动点(我不需要),我忘记从我的CSS中删除。在内容周围的div中输入
height: 100vh;
所以窗口上的滚动事件不会被触发是有意义的,因为我将在div中滚动。
相关文章:
- Selenium WebDriver and JavaScript change
- window.on.scroll事件未启动
- 组合 2 个 JavaScript .scroll 函数
- PHP and Javascript functions
- Javascript Return and if/else
- SetTimeout and clearTimeout in Javascript
- Imageslooaded无法使用Infinite Ajax Scroll和Masonry
- lightbox in html 5 and javascript
- TimelineJS and AngularJS
- timeago.js with datatable and PHP
- javascript button ajax and php
- .scroll()函数在上次更新后在谷歌chrome中定位闪烁
- Ajax and Json with Rails
- Combine onload, onresize and onclick
- 运行Infinite Scroll后调用函数时出现问题
- php布尔值's小写AND大写和数字布尔值'可以接受
- setTimeout and V8
- fadeIn fadeOut elements as you scroll up and down
- Safari and $(window).on('scroll')
- scrollHeight and clientHeight inside overflow:auto/scroll ar