The similarities and differences between jquery and Zepto

Source: Internet
Author: User

I. THE same

Originally a library developed for mobile, Zepto is a lightweight alternative to jquery because it has a similar API to jquery and smaller files. Zepto's biggest advantage is its file size, only 8k, is the smallest of the currently fully functional libraries, although not very large, Zepto provides the tools sufficient to meet the needs of the development process. Most of the common APIs and methods in jquery are Zepto, and there are some jquery in Zepto. In addition, because the Zepto API is mostly compatible with jquery, it is extremely easy to use, and if you are familiar with jquery, you can easily master Zepto. You can reuse many of the methods in jquery in the same way, or you could string together a method to get more concise code, even without looking at its documentation.

Two. Different

1, for the mobile program, zepto some basic touch events can be used to do touch screen interaction (Tap event, swipe event), Zepto is not support IE browser, this is not Zepto developer Thomas fucks on cross-browser issues, Instead, the decision to reduce file size After careful consideration, like the jquery team no longer supports the older version of IE (6 7 8) in version 2.0. Because Zepto uses jquery syntax, it suggests that jquery be used as a fallback on IE in the documentation. That way, the program can still be in IE, while other browsers can enjoy the advantages of Zepto in file size, but their two API is not fully compatible, so use this method must be careful, and to do adequate testing.

The difference between 2,dom operations: jquery does not take effect when adding an ID and zepto takes effect.

3, event-triggered differences: The handler function for the Load event is not executed when using JQuery, and the handler for the Load event is executed when using Zepto.

4, the difference between event delegates:

In Zepto, when a is clicked, it pops up with "a event" and "B event", stating that although the event delegate is on. A, it also triggers a. b delegate. But in jQuery only triggers a. A above delegate pops up "a event". In Zepto, all the click Delegate events in document are put into a queue in turn, and the current element is not when clicked. A, match then execute, then see if it is. B, compliance is performed. In jquery, 2 Click events are delegated to the document, followed by a selector to match and execute the corresponding element's delegate event.

difference between 5,width () and Height (): Zepto is determined by the box model (box-sizing), with. Width () to return the assigned width, with. css (' width ') returns the result of adding border, and jquery ignores the box model, Always returns the width/height of the content area (does not contain padding, border).

6,offset () Difference: Zepto returns {top,left,width,height};jquery return {width,height}.

7,zepto cannot get the hidden element width height, jQuery can.

There is no extend method defined for the prototype in 8,zepto and jquery has.

The each method of 9,zepto only iterates through the array and cannot traverse the JSON object.

10,zepto uses the Prop method when manipulating the selected and checked properties of the DOM, and takes precedence over attr in cases where the property value is read. Zepto the option to get the SELECT element cannot be a jquery-like method $ (' option[selected] ') because the selected property is not a standard property of CSS. You should use $ (' option '). Not (function () {return!this.selected}).

10,zepto not supported selectors:

The similarities and differences between jquery and Zepto

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.