开发者

jquery scrolltop and scrollleft work perfectly, but on iphone they all scroll the other bar to it's home position?

开发者 https://www.devze.com 2023-02-07 09:22 出处:网络
I am using the following jquery code to scroll to a certain position on the 开发者_C百科page vertically. This works absolutely fine on all browsers and does not affect the horizontal scroll position,

I am using the following jquery code to scroll to a certain position on the 开发者_C百科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


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

var isiPhone = navigator.userAgent.toLowerCase().indexOf("iphone");
var isiPad = navigator.userAgent.toLowerCase().indexOf("ipad");
var isiPod = navigator.userAgent.toLowerCase().indexOf("ipod");

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

0

精彩评论

暂无评论...
验证码 换一张
取 消