2015-01-05 53 views
0

我试图把jquery放入tumblr主题,但由于某些原因,它不会工作。我已经看了一吨的类似的问题,发现从约jQuery的教程这段代码在tumblr主题在tumblr主题jquery不会工作

<script type="text/javascript" 
    src="http://www.google.com/jsapi"></script> 

<script type="text/javascript"> 
    google.load("jquery", "1.3"); 
    google.setOnLoadCallback(function() { 
    jQuery(function($) { 
     // do some stuff here, eg load your tweets, ... 
    }); 
    }); 
</script> 

而这正是我的主题成品jQuery的部分看起来像。它的目的是制作一个无限的上下滚动(或者至少是一个幻觉),但它不适用于主题。

<head> 
    <script type="text/javascript"> 
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> 
    <script type="text/javascript"> 
    google.load("jquery", "2.0.2"); 
    google.setOnLoadCallback(function() { 
    jQuery(function($) { 
    (function($){ 
     $(document).ready(function(){ 
      var html = $(".what").html(); 
      var what = '<div class="what">'+html+'</div>'; 
      $(window).scrollTop(1); 
      $(window).scroll(function() { 
       if ($(window).scrollTop() >= ($('body').height() - $(window).height())) { 
        $(".what").last().after(what); 
        if ($(".what").length > 2) { 
         $(".what").last().prev().remove(); 
         $(window).scrollTop($(window).scrollTop() - $(".what").first().height()); 
        } 
       } 
       else if ($(window).scrollTop() == 0) { 
        $(".what").first().before(what); 
        $(window).scrollTop($(".what").first().height()); 
        if ($(".what").length > 2) { 
         $(".what").last().remove(); 
        } 
       }  
      }); 
     }); 
    })(jQuery); 

    }); 
    }); 
</script> 
</head> 
+1

'“但由于某种原因它不起作用”'不是一个很好的解释所有的问题。检查控制台是否有错误。有没有?等等 – Darren

回答

0

似乎是一个复制/粘贴错误。有一个未封闭的script标记,并且使用JavaScript API的Google API客户端库,但不包含实际的库。

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> 
<script> 
    $(document).ready(function(){ 
     var html = $(".what").html(); 
     var what = '<div class="what">'+html+'</div>'; 
     $(window).scrollTop(1); 
     $(window).scroll(function() { 
      if ($(window).scrollTop() >= ($('body').height() - $(window).height())) { 
       $(".what").last().after(what); 
       if ($(".what").length > 2) { 
        $(".what").last().prev().remove(); 
        $(window).scrollTop($(window).scrollTop() - $(".what").first().height()); 
       } 
      } 
      else if ($(window).scrollTop() == 0) { 
       $(".what").first().before(what); 
       $(window).scrollTop($(".what").first().height()); 
       if ($(".what").length > 2) { 
        $(".what").last().remove(); 
       } 
      }  
     }); 
    }); 
</script>