滚动脚本被浏览器阻止

时间:2016-08-28 22:08:19

标签: javascript jquery

我的github页面上的菜单滚动脚本有问题。由于弹出窗口,每个浏览器不断阻止js脚本。一切都像本地主机上的魅力和平板电脑或智能手机等移动设备

有代码,我想知道如何解决这个问题因为它只是导航滚动脚本与锚点,我不知道为什么整个浏览器都将其识别为弹出窗口

$(function() {
    $('#sidenav a').click(function (e) {
        e.preventDefault();

        simpleScrollTo($(this).attr('href'), 500);
    });

    $(window).scroll(function() {
        var ds = $(document).scrollTop();

        if (ds == 0) {
            $('#sidenav a').removeClass('active');
            $('#sidenav a[href=#' + $('.anchor').eq(0).attr('id') + ']').addClass('active');

            return false;
        }

        $('.anchor').each(function() {
            var $this = $(this), offset = Math.round($this.offset().top), height = $this.outerHeight() + offset;

            if (offset <= ds && height > ds) {
                $('#sidenav a').removeClass('active');
                $('#sidenav a[href=#' + $this.attr('id') + ']').addClass('active');
                if (document.location.hash != '#' + $this.attr('id')) {
                    var cds = $(document).scrollTop();
                    document.location.hash = $this.attr('id');
                    $(document).scrollTop(cds);
                }

                return false;
            }

            return true;
        });

        return true;
    });

    var ds = $(window).scrollTop();
    if (ds == 0) {
        $('#sidenav a').removeClass('active');
        $('#sidenav a[href=#' + $('.anchor').eq(0).attr('id') + ']').addClass('active');
    } else {
        $('.anchor').each(function() {
            var $this = $(this), offset = Math.round($this.offset().top), height = $this.outerHeight() + offset;

            if (offset <= ds && height > ds) {
                $('#sidenav a').removeClass('active');
                $('#sidenav a[href=#' + $this.attr('id') + ']').addClass('active');

                return false;
            }

            return true;
        });
    }
        if (document.location.hash != '') {
        var el = $(document.location.hash);
        if (el.length > 0) {
            $(window).scrollTop(0);
            $(window).load(function() {
                simpleScrollTo('#' + el.attr('id'), 1000);
            });
        }
    }
});

function simpleScrollTo(element, speed) {
    $('html:not(:animated), body:not(:animated)').animate({scrollTop: $(element).offset().top}, speed, function() {
        document.location.hash = $(element).attr('id');
    });
}

我忘了提及。我的github页面显示为“不安全”。当我允许使用不安全的脚本时,它的工作原理。它是由Github安全限制引起的吗?

1 个答案:

答案 0 :(得分:0)

解决了,没有注意到有#34; http&#34;链接为jquery而不是&#34; https&#34; :)

相关问题