我在 https://livingibogaine.squarespace.com 的 header 中引用了以下脚本.我会单独发布 HTML,但内容多如山。
脚本在 Safari 中触发效果很好! Firefox 和 Chrome 根本不阅读它们。 我的格式设置不正确吗?或者这可能是 Squarespace 平台中的错误?
<link rel="stylesheet" type="text/css" href="http://www.wlvrtn.com/sites/www.livingcleanibogaine.com/css/style-five.css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript" src="http://www.wlvrtn.com/sites/www.livingcleanibogaine.com/js/jquery.sticky.js"></script>
<script type="text/javascript">
$(window).load(function(){
$("#page-nav").sticky({ topSpacing: 0 });
});
</script>
<script type="text/javascript">
$(function() {
$('a[href*=#]:not([href=#])').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html,body').animate({
scrollTop: target.offset().top
}, 800);
return false;
}
}
});
});
</script>
最佳答案
这可能是因为您通过 https
加载页面,但通过 http
加载脚本。 Chrome 可能对做这样不安全的事情有点挑剔。尝试将 jQuery 链接更改为 src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"
并访问您的 jquery.sticky。 js
文件也来自 https 站点。
编辑:jquery.sticky.js 托管在此处的 https CDN - https://cdn.jsdelivr.net/jquery.sticky/1.0.0/jquery.sticky.min.js
关于javascript - 跨浏览器兼容性的脚本链接格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20504293/