0

我在https://livingibogaine.squarespace.com的标题中引用了以下脚本。我会单独发布 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>
4

2 回答 2

2

这可能是因为您正在加载页面https,但您的脚本已经结束http。Chrome 对做这种不安全的事情可能有点挑剔。尝试将 jQuery 链接更改为并从 https 站点src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"访问您的文件。jquery.sticky.js

编辑:jquery.sticky.js 托管在 https CDN 上 - https://cdn.jsdelivr.net/jquery.sticky/1.0.0/jquery.sticky.min.js

于 2013-12-10T20:24:39.903 回答
1

尝试使用以下代码:

<script type="text/javascript">
    jQuery(window).load(function($){
      $("#page-nav").sticky({ topSpacing: 0 });
    });
</script> 

<script type="text/javascript">
jQuery(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>

另请参阅@JoshLowry 答案

于 2013-12-10T20:24:43.823 回答