3

我正在尝试创建一个 tumblr 主题,并且正在使用 jquery 的砖石和无限滚动插件。砌体工作得很好。但是,我根本无法让无限滚动工作。这是我的 jQuery 代码:

<script type="text/javascript" src="../jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="../masonry.js"></script>
<script type="text/javascript" src="../jquery.infinitescroll.js"></script>
<script type="text/javascript">
$('document').ready(function(){
$('#content').imagesLoaded(function(){
$('#content').masonry({
itemSelector: '.post',
columnWidth: 260});
});
$('#content').infinitescroll({
    navSelector  : '#nav',
    nextSelector : '#nav a',
    itemSelector : '#content div.post',          
    },
    function( newElements ) {
    var $newElems = $( newElements );
    $('#content').masonry( 'appended', $newElems, function(){$newElems.fadeIn('slow');}   );
  });
});
</script>

这是我的 HTML:

 <div id="content">
   {block:Posts}
   {block:Photo}
<div class="post">
<img src="{PhotoURL-250}" width="250" />
</div>
   {/block:Photo}
   {/block:Posts}
 {block:Pagination}
<div id="nav">{block:NextPage}<a href="{NextPage}"></a>{/block:NextPage}</div>
 {/block:Pagination}

任何帮助是极大的赞赏。提前致谢。

*我还想指出,我故意缩短了 js 文件的 URL,只是为了使帖子看起来更好,在我的实际主题上,URL 是正确的。

这是我添加调试后控制台显示的内容(老实说,我真的不知道这意味着什么,但希望它有所帮助)

Testing console
["determinePath", 
Array[2]
0: "/page/"
1: ""
length: 2
__proto__: Array[0]
] jquery.infinitescroll.js:171
["Binding", "bind"] jquery.infinitescroll.js:171
["math:", 77, 644] jquery.infinitescroll.js:171
["heading into ajax", 
Array[2]
0: "/page/"
1: ""
length: 2
__proto__: Array[0]
] jquery.infinitescroll.js:171
["Using HTML via .load() method"] jquery.infinitescroll.js:171
["contentSelector", 
<div id=​"content" style=​"position:​ relative;​ height:​ 689px;​ " class=​"masonry">​…​&lt;/div>​
] jquery.infinitescroll.js:171
["math:", 292, 644] jquery.infinitescroll.js:171
["heading into ajax", 
Array[2]
] jquery.infinitescroll.js:171
["Using HTML via .load() method"] jquery.infinitescroll.js:171
["Error", "end"] jquery.infinitescroll.js:171
["Binding", "unbind"] 
4

1 回答 1

5

一些浏览器因仅支持 window.console 的子集甚至根本不支持而臭名昭著。一些浏览器仅支持 console.info,而其他浏览器支持 info、debug、log、warn、error 和可能的其他。

在 jquery.infinitescroll.js 文件的第 171 行或附近,您将找到以下代码:

    // Console log wrapper
    _debug: function infscr_debug() {

        if (this.options && this.options.debug) {
            return window.console && console.log.call(console, arguments);
        }

    },

在 Internet Explorer 中,有时未定义控制台方法,除非启用了开发人员工具和/或脚本调试器功能;因此,在开发人员计算机上运行良好的 Web 应用程序在开发人员工具和/或脚本调试器被禁用的生产计算机上使用时可能会严重失败。

作为开发人员,您的第一直觉可能是从您的代码中删除控制台语句——或者您正在使用的任何库的代码中使用 console.log。更糟糕的是,您可能会避免使用控制台语句,而使用警报。

由于 console.log 语句对于故障排除和调试过程非常有价值,因此可以用来确保控制台语句不会干扰生产代码的一种技术是在所有网页上包含控制台对象的默认定义,其中出现此问题:

此 JavaScript 在包含在<head>您的页面部分中时,将定义 window.console 及其方法为空函数,如果它检测到它们尚未定义。

<script type="text/javascript"> 
// override loggers to avoid throwing errors
if(window.console == null || window.console == undefined || !window.console) {
           console = { log: function() {}, info: function() {}, warn: function() {}, error: function() {}, trace: function() {}, debug: function() {} };
           //var fbscript = document.createElement("script");
           //fbscript.src = "https://getfirebug.com/firebug-lite-beta.js";
           //fbscript.setAttribute("type","text/javascript");
           //document.getElementsByTagName("head")[0].appendChild(fbscript);
} else if(!console.debug) {
         console.debug = function(text) { if(console.log) console.log("D: "+text); };
}
</script>

此外,如果 window.console 为 null 或未定义,则有 4 行注释的 JavaScript 将在您使用的任何浏览器中加载 Firebug Lite。

或者,您可以检查以确保您没有在 jQuery Infinite 滚动插件本身的选项部分中打开调试:

     debug        : true,                        
             // enable debug messaging ( to console.log )

Ideally, this would probably be a better solution, but I prefer the former since I know it helps me avoid the trap of not testing in browsers with no debuggers.

See the jQuery Ininite Scroll documentation, specifically, the options section, for more details.

于 2012-05-23T02:25:56.653 回答