使用动画无法在IE上平滑滚动效果

时间:2019-02-07 10:22:18

标签: javascript jquery scroll navigation

我有一个功能,在单击菜单项时,它会滚动到下一页的该部分。这在Firefox,chrome,edge上非常流畅,但是在IE上,单击菜单项后,您将直接转到部分没有滚动效果。 但是,当我单击同一页面上的不同项目时,滚动效果确实可以正常工作。仅当从一页转到另一页时,滚动效果不起作用。

Js代码

var hashURL = location.hash;
    if (hashURL != "" && hashURL.length > 1) {
        $(window).scrollTop(0); 
        setTimeout(function () {    
            smoothScrollTo(hashURL)
        }, 1500);
    }

function smoothScrollTo(anchor) {
        var topMenuHeight = $('header').outerHeight()
        var duration = 800; 
        var targetY;
        if($(anchor).length > 0) {   
            if (currentDevice == "desktop" || currentDevice == "ipad-landscape") {
                    targetY = $(anchor).offset().top - 159 + 63
                }else{
                    targetY = $(anchor).offset().top - topMenuHeight 
                }
                $("html, body").animate({
                    "scrollTop": targetY
                    }, duration, 'linear');
            }
        }

请帮助。

0 个答案:

没有答案