What are the similarities and differences between jQuery and Zepto?

coldplay.xixi
Release: 2020-12-22 15:43:42
Original
8363 people have browsed it

Similarities and differences between jQuery and Zepto: 1. The same point is that Zepto was originally developed as a library for mobile terminals and is a lightweight substitute for jQuery. If you are familiar with jQuery, you can easily master Zepto; 2. Differences When you click to add the id, jQuery will not take effect but Zepto will.

What are the similarities and differences between jQuery and Zepto?

The operating environment of this tutorial: Windows 7 system, jquery version 3.2.1. This method is suitable for all brands of computers.

Similarities and differences between jQuery and Zepto:

1. Same as

Zepto was originally a library developed for mobile terminals. A lightweight alternative to jQuery because its API is similar to jQuery and its file size is smaller. Zepto's biggest advantage is its file size, which is just over 8k. It is the smallest among the currently fully functional libraries. Although it is not large, the tools provided by Zepto are sufficient to meet the needs of developing programs. Most of the commonly used APIs and methods in jQuery are available in Zepto, and there are some in Zepto that are not found in jQuery. In addition, because most of Zepto's APIs are compatible with jQuery, it is extremely easy to use. If you are familiar with jQuery, you can easily master Zepto. You can reuse many methods in jQuery in the same way, and you can also string methods together to get cleaner code, without even looking at its documentation.

2. Differences

1. For mobile programs, Zepto has some basic touch events that can be used for touch screen interaction (tap events, swipe events), Zepto It does not support the IE browser. This is not because Zepto developer Thomas Fucks was confused on the cross-browser issue, but a decision made after careful consideration in order to reduce the file size, just like the jQuery team in 2.0 Older versions of IE (6 7 8) are no longer supported in this version. Because Zepto uses jQuery syntax, it recommends jQuery as a fallback library on IE in its documentation. That way the program can still run in IE, and other browsers can enjoy the file size advantage of Zepto. However, the APIs of the two are not fully compatible, so be careful and do sufficient research when using this method. test.

 2. The difference between Dom operations: jQuery will not take effect when adding an id, but Zepto will.

(function($) { $(function() { var $insert = $('

jQuery 插入

', { id: 'insert-by-jquery' }); $insert.appendTo($('body')); }); })(window.jQuery); //

jQuery 插入

Zepto(function($) { var $insert = $('

Zepto 插入

', { id: 'insert-by-zepto' }); $insert.appendTo($('body')); }); //

Zepto 插入

Copy after login

3. The difference in event triggering: when using jQuery, the handler function of the load event will not be executed; when using Zepto, the handler function of the load event will be executed.

(function($) { $(function() { $script = $('