jQuery scrollLeft无法正常工作 [英] jQuery scrollLeft not working

查看:66
本文介绍了jQuery scrollLeft无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚推出了 http://elliewauters.com &有一个我想修复的问题,该网站使用了很多动画水平滚动从一个'页面'到下一个,但刷新大多数浏览器时记住滚动位置和放大器。回到我以前的地方,我不想要这个。尝试进入关于页面&然后刷新。你会看到徽标&菜单位于页面中间,因为它们是您第一次到达网站时的位置。

I just launched http://elliewauters.com & have a little problem that I'd like to fix, the site uses a lot of animated horizontal scrolling to go from one 'page' to the next, but on refresh most browsers remember the scroll position & go back to where I was before, I do not want this. Try going to the 'About' page & then refreshing. You'll see that the logo & menu are in the middle of the page as they where when you arrived at the site for the first time.

我希望得到以下两种方面的帮助:


  1. 在页面刷新时将滚动位置重置为0,0或

  2. 移动徽标&如果scrollLeft值大于1,则菜单位于顶部。

我尝试使用 $(窗口) .scrollLeft(0); 无济于事

scrollLeft = $(window).scrollLeft();
console.log(scrollLeft)
if (scrollLeft>1) {
    $('#header').addClass('notLeft').css('top','0%');
} else {
    $('#header').addClass('left').css('top','25%');
}

不起作用,有没有人请知道如何实现目标我想要吗?

does not work, does anyone please have an idea of how I could achieve what I want?

提前致谢

推荐答案

好的Firefox不是'因为 console.log(scrollLeft)而工作,所以它应该在删除后工作。至于你遇到的问题,我猜它只发生在IE?解决方案是不使用 $(窗口),而是将其替换为 $(document)。所以使用:

Well Firefox wasn't working because of the console.log(scrollLeft) so it should work after removing that. As for the problem you are having, I'm guessing it is only happening in IE? The solution is to not use $(window) but instead replace it with $(document). So use:

scrollLeft = $(document).scrollLeft();

这篇关于jQuery scrollLeft无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆