jquery的scrolltop和scrollleft工作得很好,但是在iphone上它们都将另一个栏滚动到它的起始位置?
我使用以下 jquery 代码垂直滚动到页面上的某个位置。这在所有浏览器上都工作得很好,并且不会影响水平滚动位置,但是当我在 iphone(在移动 safari 上)上尝试它时,除了垂直滚动到正确的位置之外,它还会一直水平滚动到左侧。同样,如果我使用scrollleft,它将水平转到正确的位置,但会返回到页面顶部。它在其他方面都工作得很好,我在任何地方都找不到任何关于这个问题的参考,如果任何遇到这个问题的人可以帮助我,因为我被难住了,我将非常感激!我什至无法一个接一个地执行(向左滚动然后向右滚动),因为无论我最后执行哪一项都会取消前一项设置的滚动位置。
if($.browser.opera)
{
$('html').animate(
{
scrollTop: yscroll - 10
},
1000);
}
else
{
$('html, body').animate(
{
scrollTop: yscroll - 10
},
1000);
}
非常感谢您的帮助!
戴夫
I am using the following jquery code to scroll to a certain position on the page vertically. This works absolutely fine on all browsers and does not affect the horizontal scroll position, however when i try it on an iphone (on mobile safari) in addition to scrolling to the correct place vertically it also scrolls horizontally all the way to the left. Similarly if i use scrollleft it will go to the correct place horizontally but will return to the top of the page. It works fine on everything else and i cannot find any reference to this problem anywhere, i would be immensely grateful if anyone who's come across this could help me out as i'm stumped! I can't even do one after the other (scrollleft then scrollright) as whichever one i do last will cancel out the scroll positon set by the previous one.
if($.browser.opera)
{
$('html').animate(
{
scrollTop: yscroll - 10
},
1000);
}
else
{
$('html, body').animate(
{
scrollTop: yscroll - 10
},
1000);
}
Thanks so much for your help!
Dave
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许你可以首先获取当前的scrollLeft(或scrollTop,如果你对scrollLeft进行动画处理)值,然后当用户代理告诉你这是一个iphone时,对scrollLeft和scrollTop进行动画处理,
这不是最好的,因为你将有一个不同的动画,但至少你会在同一位置结束
iphone/pad iPad / jQuery.animate(scroll) issues
maybe you could first get the current scrollLeft (or scrollTop if you animate scrollLeft) value and then animate both scrollLeft and scrollTop when the user agents tell you it's an iphone
it's not the best since you will have a different animation, but at least you will end on the same position
there's some issue with iphone/pad iPad / jQuery.animate(scroll) issues