1.width()/height()

  • Zepto.js: 由盒模型(box-sizing)决定

jQuery: 忽略盒模型,始终返回内容区域的宽/高(不包含 paddingborder

jQuery 官方的说明

Note that .width() will always return the content width, regardless of the value of the CSS box-sizingproperty. As of jQuery 1.8, this may require retrieving the CSS width plus box-sizing property and then subtracting any potential border and padding on each element when the element has box-sizing: border-box. To avoid this penalty, use .css("width") rather than .width().

解决方式就是在 jQuery 中使用 .css('width'),而不是 .width()

这点上 jQuery 的处理方式是值得商榷的,比如下面的例子,$('.box').css('height') 仍然返回 20px,这不是扯蛋么:

<style>
.box {
box-sizing: border-box;
padding: 10px;
height:;
}
</style> <div class="box"></div>
边框三角形宽高的获取

假设用下面的 HTML 和 CSS 画了一个小三角形:

<div class="caret"></div>
.caret {
width:;
height:;
border-width: 0 20px 20px;
border-color: transparent transparent blue;
border-style: none dotted solid;
}
  • jQuery 使用 .width() 和 .css('width') 都返回 0,高度也一样;
  • Zepto 使用 .width() 返回 40,使用 .css('width') 返回 0px

所以,这种场景,jQuery 使用 .outerWidth()/.outerHeight();Zepto 使用 .width()/.height()

2.offset()

    • Zepto.js: 返回 topleftwidthheight
    • jQuery: 返回 widthheight

$(htmlString, attributes)

DOM 操作区别
$(function() {
var $list = $('<ul><li>jQuery 插入</li></ul>', {
id: 'insert-by-jquery'
});
$list.appendTo($('body'));
});

jQuery 操作 ul 上的 id 不会被添加;Zepto 可以在 ul 上添加 id

事件触发区别
$script = $('<script />', {
src: 'http://cdn.amazeui.org/amazeui/1.0.1/js/amazeui.min.js',
id: 'ui-jquery'
}); $script.appendTo($('body')); $script.on('load', function() {
console.log('jQ script loaded');
});

使用 jQuery 时 load 事件的处理函数不会执行;使用 Zepto 时 load 事件的处理函数会执行。

JQuery和Zepto的差异(部分)的更多相关文章

  1. jquery和zepto的扩展方法extend

    jquery和zepto的扩展方法extend 总结下jQuery(3.1.1)和zepto(1.1.6)到底是如何来开放接口,使之可以进行扩展,两者都会有类型判断,本文使用简单的类型判断,暂不考虑兼 ...

  2. HBuilder支持jquery、zepto、angular、ext、dojo 等js框架的提示吗

    HBuilder有通行的js扫描分析提示,大部分js库都可以方便的提示.但js是一门超级灵活的语言,通行分析有时分析的不够完美,如果对框架做单独优化配置,可以有更好的提示.DCloud官方对jquer ...

  3. jQuery与Zepto

    jQuery和Zepto是我比较常用的插件.其实用法差不太多,可以说Zepto是jQuery的轻量级替代品,但是不要认为Zepto就没有jQuery好用,因为Zepto有jQuery没有的功能,就是移 ...

  4. 解决jquery与zepto等其它库冲突兼容的问题

    解决jquery与zepto等其它库冲突兼容的问题;(function ($) {    }) (jQuery); ;(function ($) {    }) (Zepto); 在Bootstrap ...

  5. zepto jquery和zepto的区别?

    jQuery 由于强大的生命力基本上是一个事实标准,所以大部分工具 lib 在 DOM 操作.动画等功能上或多或少都会是 jQuery-like 的. Zepto 的 API 就是完全兼容 jQuer ...

  6. jquery和zepto的异同

    相同点 相同点: zepto: 是jquery 的 阉割版 是为移动端开发的库 jQuery的轻量级替代品.文件大小比较小 只有8k左右 ,是目前功能库中最小的一个,尽管不大,zepto 所提供的工具 ...

  7. jQuery与Zepto的异同

    一,同: Zepto最初是为移动端开发的库,是jQuery的轻量级替代品,因为它的API和jQuery相似,而文件更小.Zepto最大的优势是它的文件大小,只有8k多,是目前功能完备的库中最小的一个, ...

  8. jQuery和Zepto冲突问题【解决】

    特殊操作下,项目中同时引入这两个文件时,往往会有些冲突,应该加一句代码避免冲突 <script src="~/js/jquery-2.1.4.js"></scri ...

  9. 复习 | 重温jQuery和Zepto的API

    jq和zepto很相似有许多共同的api,zepto也出了很多与jq不一样的api,总的来说,两者更相似,但是zepto更轻量一点,正好公司也在用,复习这两个没错 jq中的zepto的事件和ajax我 ...

随机推荐

  1. KS检验学习[转载]

    转自:https://wenku.baidu.com/view/ccfa573a3968011ca30091d6.html https://www.cnblogs.com/arkenstone/p/5 ...

  2. PAT 1100 Mars Numbers[难]

    1100 Mars Numbers (20 分) People on Mars count their numbers with base 13: Zero on Earth is called &q ...

  3. sysbench压测mysql基本步骤

    MySQL数据库测试 select   1.先创建数据库test,再准备数据 time /usr/local/sysbench/bin/sysbench --test=oltp --num-threa ...

  4. OA项目_环境搭建

    OA项目现在要做成微服务,用的框架是springboot,所用的编程工具是idea,maven,做为一个程序员最关心的就是我需要在那个架包中编写代码,我们只需关注domain,repository,s ...

  5. php array_map array_filter sort

    array_map — Applies the callback to the elements of the given arrays (处理映射) array_filter — Filters e ...

  6. linux改变apt-get安装源

    最近自己装了个ubuntu kylin 在使用的过程中发现,系统的apt-get 的源有毛病,总是安装不了软件. 感觉应该是传说中的墙的原因,所以准备换到阿里云的源. 下面是步骤: 1.复制原文件备份 ...

  7. Bootstrap table前端分页(ssm版)

    说明bootstrap table可以前端分页,也可以后端sql用limit分页.前端分页下性能和意义都不大,故一般情况下不用这种,请看我的另一篇后端分页的博客源码下载地址:https://git.o ...

  8. MapReduce: map读取文件的过程

    我们的输入文件 hello0, 内容如下: xiaowang 28 shanghai@_@zhangsan 38 beijing@_@someone 100 unknown 逻辑上有3条记录, 它们以 ...

  9. springcloud8----feign-with-hystrix

    Feign也可以使用Hystrix: package com.itmuch.cloud; import org.springframework.boot.SpringApplication; impo ...

  10. myeclips破解

    MyEclipse官方安装文件,下载地址 http://www.jb51.net/softs/150886.html破解补丁http://www.jb51.net/softs/150887.html ...