gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 05:27:01 25 4
gpt4 key购买 nike

我的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com