简体   繁体   中英

ScrollTop and ScrollTo is not working with ipad

I have the issue with IPad where i am calculating position to navigate to the sections based on menu selection. It works fine with all desktop with all the browsers except IPad. I tried using window.scrollTo and other options suggested by stackoverflow.But no luck.

Below is the code .

        function goToNav(anchor)
        {
            var tbarOffset = $("toolbar").offsetTop;
            var header = document.getElementById("tab1_"+anchor);
            var pos1 = header.offsetTop;
            var pos2 = header.offsetParent.offsetTop;
            var pos3 = header.firstChild.offsetHeight;
            if(tbarOffset==0)
            {
                var pos = ((pos1 + pos2) - pos3);
            }
            else
            {
                var pos = ((pos1 + pos2) - pos3)- pos3;
            }

            document.documentElement.scrollTop  = pos;
            document.body.scrollTop = pos;
            }
        }

Appreciate your help on this.

Thanks, Venu

Scroll is an event, so you have to listen for that event.

Something like this:

    addEventListener('scroll', function() {            
        if (timer !== null) {
            clearTimeout(timer);
        }

        timer = setTimeout(function() {                
            // ... do something
            goToNav(//param);

            if(timer === null)
                setTimeout(arguments.callee, 10);
        }, 10);

    }, false);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM