javascript - 滚动脚本被浏览器阻止

标签 javascript jquery

我的 github 页面上的菜单滚动脚本有问题。每个浏览器都会因为弹窗而不断阻塞js脚本。在本地主机和平板电脑或智能手机等移动设备上,一切都运转良好

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

$(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安全限制导致的吗?

最佳答案

已解决,没有注意到 jquery 有“http”链接而不是“https”:)

关于javascript - 滚动脚本被浏览器阻止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39196246/

相关文章:

javascript - 识别动态创建的 svg 元素

jquery - 如何在网页上创建 float 搜索栏

javascript - Jquery Timeago 插件可与 unix 时间戳一起使用

javascript - 从另一个 html 文件追加 div

javascript - D3 放大笔刷范围

javascript - Vue 中的实时正则表达式模式替换

javascript - 什么时候不应该使用允许跨域?

javascript - JavaScript 中的转义双引号

javascript - JQuery 中的行计数

javascript - 图像地板褪色颜色与网页背景颜色混合?