我试图将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>发布于 2015-01-05 17:42:13
似乎是复制/粘贴错误。这里有一个未关闭的script标记,使用的是JavaScript的Google API客户端库,但没有包含actually库。
<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>https://stackoverflow.com/questions/27772849
复制相似问题