3

我曾经使用 jQuery 并且正在使用

我现在使用zepto.js而不是 jQuery,当然现在插件都通过以下错误。

未捕获的 ReferenceError:未定义 jQuery

如果我将两个插件都更新})(jQuery);})(Zepto);以下错误...</p>

未捕获的类型错误:无法读取未定义的属性“:”

有什么想法吗?是否可以使这些插件与 Zepto 一起使用?Zepto 不是与 Jquery 几乎相同,只是没有旧的浏览器兼容性和额外的触摸事件?

先感谢您。

马特

4

2 回答 2

3

导致错误的行似乎是:

.extend($.expr[':'], {

jQuery uses its own CSS-style selector evaluator called Sizzle. In addition to letting you use $('#id .cls1 .cls2, #otherid') and standard CSS pseudo-selectors, it supports extension with custom selectors like the built-in :visible selector or the :above-the-fold selector provided by this plugin.

Since modern mobile browser support the native document.querySelectorAll function for CSS selection, a library like Sizzle isn't needed, saving a significant amount of JavaScript. (That's why we love Zepto.) The side effect is that these custom selectors aren't supported and $.expr doesn't exist. Any line that depends on these, including that line in the plugin will fail.

The good news is that these are convenience selectors and you may just be able to cut them out of your script. If you don't want to find elements above and below the fold this way, you can just cut them out of the code. You will also need to address the line where the library calls $this.is(":visible") but other than that I don't really see anything too jQuery-specific.

于 2012-07-05T18:28:43.807 回答
0

You also need to deal with $window.scrollLeft(), which isn't implemented in Zepto (you can use window.pageXOffset).

I've implemented full Zepto compatibility on my branch: https://github.com/adamvert/jquery_lazyload

于 2013-08-26T10:02:38.690 回答