Jquery Animate ScrollLeft doesnt work on ipad

2019-09-12 05:39发布

问题:

So im developing this site it works perfectly on pc and mac but on ipad im having problems with the navigation.

http://remedia-solutions.com/clientes/0039_kiplingmexico/demo2/

This code moves the html,body to another section. It works perfectly on pc and mac. But when im on ipad it just doesnt work.

In this case it moves to the index section.

$("#ini").click(function() {
        if($("#todolocal").css("left") == '0px'){
            $("#todolocal").animate({left: '3500px'}, 1000,'easeInOutQuad',function(){
            $("#todolocal").css('left', '-2500px')
            $('html,body').stop(true,false).animate({
                scrollLeft: $("#todoini").offset().left ,
                scrollTop: 0}, 650);
         $('#todoini').stop(true,false).animate({
                scrollTop: 0 }, 650);
                lugar= 0;
                window.location.hash = '';
                document.title="Kipling: Inicio";
                $("#ini").addClass('focusini');
                $("#hist").removeClass('focushist');
                $("#col").removeClass('focuscoleccion');
                $("#cuid").removeClass('focuscuidados');
                $("#suc").removeClass('focussucursales');
                $("#cont").removeClass('focuscontacto');
                return false;
        });
        }
        if($("#todobolsas").css("left") == '0px'){
            $("#todobolsas").animate({left: '3500px'}, 1000,'easeInOutQuad',function(){
            $("#todobolsas").css('left', '-2500px')
            $('html,body').stop(true,false).animate({
                scrollLeft: $("#todoini").offset().left ,
                scrollTop: 0}, 650);
         $('#todoini').stop(true,false).animate({
                scrollTop: 0 }, 650);
                lugar= 0;
                window.location.hash = ''
                document.title="Kipling: Inicio";
                $("#ini").addClass('focusini');
                $("#hist").removeClass('focushist');
                $("#col").removeClass('focuscoleccion');
                $("#cuid").removeClass('focuscuidados');
                $("#suc").removeClass('focussucursales');
                $("#cont").removeClass('focuscontacto');
                return false;
        });
        }
        else{
        $('html,body').stop(true,false).animate({
                scrollLeft: $("#todoini").offset().left ,
                scrollTop: 0}, 650);
         $('#todoini').stop(true,false).animate({
                scrollTop: 0 }, 650);
                lugar= 0;
                window.location.hash = ''
                document.title="Kipling: Inicio";
                $("#ini").addClass('focusini');
                $("#hist").removeClass('focushist');
                $("#col").removeClass('focuscoleccion');
                $("#cuid").removeClass('focuscuidados');
                $("#suc").removeClass('focussucursales');
                $("#cont").removeClass('focuscontacto');
                return false;
            }
    });

Any ideas?

回答1:

I solve it by animating only once at a time not at the same time and it worked :)

$('html,body').stop(true,false).animate({
                scrollLeft: $("#todoini").offset().left}, 650,function(){
                    $(this).stop(true,false).animate({scrollTop:0})
                });
         $('#todoini').stop(true,false).animate({
                scrollTop: 0 }, 650);
                lugar= 0;
                window.location.hash = '';
                document.title="Kipling: Inicio";
                $("#ini").addClass('focusini');
                $("#hist").removeClass('focushist');
                $("#col").removeClass('focuscoleccion');
                $("#cuid").removeClass('focuscuidados');
                $("#suc").removeClass('focussucursales');
                $("#cont").removeClass('focuscontacto');


回答2:

Are you explicitly setting your moving elements left CSS property prior to the loading of your JavaScript? Also when animating left, top etc. you can just do left: 350. There's no need to encapsulate in quotes with the px.