JQuery和Zepto的差异(部分)
1.width()/height()
- Zepto.js: 由盒模型(
box-sizing)决定
jQuery: 忽略盒模型,始终返回内容区域的宽/高(不包含 padding、border)
jQuery 官方的说明:
Note that
.width()will always return the content width, regardless of the value of the CSSbox-sizingproperty. As of jQuery 1.8, this may require retrieving the CSS width plusbox-sizingproperty and then subtracting any potential border and padding on each element when the element hasbox-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: 返回
top、left、width、height - jQuery: 返回
width、height
- Zepto.js: 返回
$(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的差异(部分)的更多相关文章
- jquery和zepto的扩展方法extend
jquery和zepto的扩展方法extend 总结下jQuery(3.1.1)和zepto(1.1.6)到底是如何来开放接口,使之可以进行扩展,两者都会有类型判断,本文使用简单的类型判断,暂不考虑兼 ...
- HBuilder支持jquery、zepto、angular、ext、dojo 等js框架的提示吗
HBuilder有通行的js扫描分析提示,大部分js库都可以方便的提示.但js是一门超级灵活的语言,通行分析有时分析的不够完美,如果对框架做单独优化配置,可以有更好的提示.DCloud官方对jquer ...
- jQuery与Zepto
jQuery和Zepto是我比较常用的插件.其实用法差不太多,可以说Zepto是jQuery的轻量级替代品,但是不要认为Zepto就没有jQuery好用,因为Zepto有jQuery没有的功能,就是移 ...
- 解决jquery与zepto等其它库冲突兼容的问题
解决jquery与zepto等其它库冲突兼容的问题;(function ($) { }) (jQuery); ;(function ($) { }) (Zepto); 在Bootstrap ...
- zepto jquery和zepto的区别?
jQuery 由于强大的生命力基本上是一个事实标准,所以大部分工具 lib 在 DOM 操作.动画等功能上或多或少都会是 jQuery-like 的. Zepto 的 API 就是完全兼容 jQuer ...
- jquery和zepto的异同
相同点 相同点: zepto: 是jquery 的 阉割版 是为移动端开发的库 jQuery的轻量级替代品.文件大小比较小 只有8k左右 ,是目前功能库中最小的一个,尽管不大,zepto 所提供的工具 ...
- jQuery与Zepto的异同
一,同: Zepto最初是为移动端开发的库,是jQuery的轻量级替代品,因为它的API和jQuery相似,而文件更小.Zepto最大的优势是它的文件大小,只有8k多,是目前功能完备的库中最小的一个, ...
- jQuery和Zepto冲突问题【解决】
特殊操作下,项目中同时引入这两个文件时,往往会有些冲突,应该加一句代码避免冲突 <script src="~/js/jquery-2.1.4.js"></scri ...
- 复习 | 重温jQuery和Zepto的API
jq和zepto很相似有许多共同的api,zepto也出了很多与jq不一样的api,总的来说,两者更相似,但是zepto更轻量一点,正好公司也在用,复习这两个没错 jq中的zepto的事件和ajax我 ...
随机推荐
- 【开发者笔记】揣摩Spring-ioc初探,ioc是不是单例?
前言: 控制反转(Inversion of Control,英文缩写为IoC)把创建对象的权利交给框架,是框架的重要特征,并非面向对象编程的专用术语.它包括依赖注入(Dependency Inject ...
- angry_birds_again_and_again(2014年山东省第五届ACM大学生程序设计竞赛A题)
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2877 题目描述 The problems ca ...
- t检验&z检验学习[转载]
转自:https://blog.csdn.net/m0_37777649/article/details/74937242 1.什么是T检验? T检验是假设检验的一种,又叫student t检验(St ...
- Windows Server 2008 R2(X64) MSDN镜像简体中文版与英文版ISO下载及Key激活码
Windows Server 2008 R2 MSDN ISO镜像简体中文版 文件名:cn_windows_server_2008_r2_standard_enterprise_datacenter_ ...
- forEach方法的实现
var arr = [1, 23, 1, 1, 1, 3, 23, 5, 6, 7, 9, 9, 8, 5]; Array.prototype.forEach = Array.prototype.fo ...
- poj1329 Circle Through Three Points
地址:http://poj.org/problem?id=1329 题目: Circle Through Three Points Time Limit: 1000MS Memory Limit: ...
- python学习之【16】网络编程
主题 客户端/服务器架构 套接字:通信终点 套接字地址 面向连接与无连接套接字 Python中的网络编程 SOCKET模块 套接字对象方法 TCP/IP客户端和服务器 UDP/IP客户端和服务器 So ...
- CyclicBarrier实现流水处理服务类
package com.yzu.zhang.thread.concurrent; import java.util.Map.Entry; import java.util.Random; import ...
- STM32|4-20mA输出电路(转)
源:STM32|4-20mA输出电路 STM32+运算放大器实现VI转换,4mA-20mA发送器
- Git提交撤销
场景:本地修改代码后,执行commit提交,但此时想撤销该提交. 执行命令: git reflog 查看所有commit历史 git reset --hard commitid 将当前远程 ...