从其他网站平滑滚动

时间:2016-04-17 18:54:19

标签: javascript jquery scroll smooth

目前我正在使用以下脚本获得平滑的滚动效果:

$(document).ready(function () {
$(document).on("scroll", onScroll);

//smoothscroll
$('a[href^="#"]').on('click', function (e) {
    e.preventDefault();
    $(document).off("scroll");

    $('a').each(function () {
        $(this).removeClass('active');
    })
    $(this).addClass('active');

    var target = this.hash,
        menu = target;
    $target = $(target);
    $('html, body').stop().animate({
        'scrollTop': $target.offset().top+2
    }, 500, 'swing', function () {
        window.location.hash = target;
        $(document).on("scroll", onScroll);
    });
});
});

function onScroll(event){
var scrollPos = $(document).scrollTop();
$('#menu-center a').each(function () {
    var currLink = $(this);
    var refElement = $(currLink.attr("href"));
    if (refElement.position().top <= scrollPos && refElement.position().top + refElement.height() > scrollPos) {
        $('#menu-center ul li a').removeClass("active");
        currLink.addClass("active");
    }
    else{
        currLink.removeClass("active");
    }
});
}`

OnePager一切正常。但如果我在en&#34;外部网站&#34;例如隐私政策并点击菜单上没有任何反应。这可能是因为在脚本中我停用了链接并用滚动替换了它。我在jQuery中不是那么好,你能帮助我,以便它也可以运行形式&#34;外部&#34;网站?我需要添加什么代码?

问候

0 个答案:

没有答案