Home >Web Front-end >JS Tutorial >What are the differences between jQuery and Zepto
Differences: 1. In Zepto, a large amount of jQuery compatible code has been removed for the mobile terminal; 2. The handler function of the load event will not be executed when using jQuery; the handler function of the load event will be executed when using Zepto; 3 , zepto does not define the extend method for the prototype, but jquery does.
The operating environment of this tutorial: windows10 system, jquery2.2.4, this article is applicable to all brands of computers.
The difference between jQuery and Zepto
1. Zepto is more lightweight
2. Zepto is a streamlined version of jQuery, removing a lot of them for mobile terminals jQuery compatible code
3. Some APIs are implemented differently
1). For mobile programs, Zepto has some basic touch events that can be used for touch screen interaction (tap events, swipe event), Zepto does not support IE browser.
2), the difference between DOM operations: jQuery will not take effect when adding id, but Zepto will take effect
(function($) { $(function() { var $insert = $('<p>jQuery 插入</p>', { id: 'insert-by-jquery' }); $insert.appendTo($('body')); }); })(window.jQuery); // <p>jQuery 插入<p> Zepto(function($) { var $insert = $('<p>Zepto 插入</p>', { id: 'insert-by-zepto' }); $insert.appendTo($('body')); }); // <p id="insert-by-zepto">Zepto 插入</p>
3), the difference between event triggering: when using jquery, the load event handler will not Execution; when using zepto, the handler function of the load event will be executed
(function($) { $(function() { $script = $('<script />', { src: 'http://cdn.amazeui.org/amazeui/1.0.1/js/amazeui.js', id: 'ui-jquery' }); $script.appendTo($('body')); $script.on('load', function() { console.log('jQ script loaded'); }); }); })(window.jQuery); Zepto(function($) { $script = $('<script />', { src: 'http://cdn.amazeui.org/amazeui/1.0.1/js/amazeui.js', id: 'ui-zepto' }); $script.appendTo($('body')); $script.on('load', function() { console.log('zepto script loaded'); }); });
4), the difference between event delegation: in zepto, all delegated events on the selector are put into a queue in turn, while in jquery Then delegate it into multiple independent events
5), the difference between width() and height(): zepto is determined by the box model (box-sizing), use .width() to return the assigned width, use . css('width') returns the results of border, etc.; jquery ignores the box model and always returns the width/height of the content area (excluding padding and border).
6), the difference between offset(): zepto Return {top,left,width,height}; jquery returns {width,height}. zepto cannot obtain the width and height of hidden elements, jquery can
7), zepto does not define the extend method for the prototype, but jquery has
8), zepto's each method can only traverse the array, not Iterate over JSON objects.
jQuery and Zepto.js look similar on the surface. In fact, some details are very different. Supporting jQuery and Zepto.js at the same time is a thankless task. This should be the reason why Foundation 5 gave up supporting Zepto. reason.
For more programming-related knowledge, please visit: Programming Video Course! !
The above is the detailed content of What are the differences between jQuery and Zepto. For more information, please follow other related articles on the PHP Chinese website!