用Zepto代替Jquery提升移动Web用户体验

jQuery现在已经是Web开发者比较依赖的一个库.甚至在很多公司内部也把jQuery当成了一个基本库来使用.

对于移动端压缩后100k左右的jQuery显得有些重量级了,于是就出现了一个轻量级兼容库Zepto.js.

Zepto是为了支持移动端的浏览器而开发的一个和jQuery API极度相似的一个库, 如果你会用jquery,那么你也会用zepto,这样就大大降低团队协作的成本,不用改变开发习惯也能迅速的进行移动端开发.

Zepto设计的目的是提供jquery的类似的APIs,但并不是100%覆盖jquery为目的。zepto设计的目的是有一个5-10k的通用库、下载并执行快、有一个熟悉通用的API,所以你能把你主要的精力放到应用开发上。

具体到我们的项目,由于各种原因,开始时并没有使用Zepto而是使用了Jquery。这次性能优化打算换成Zepto,毕竟size查了10倍啊。但是简单的把js引入替换成zeptp显然是不行的。由于用了lazyload等插件,依赖了jQuery的$.Defered, 还用了css3的一些selector,因此还有需要引入Zepto的一些扩展模块,Zepto默认提供的压缩文件只包含几个默认模块,可以通过命令自定义打包其它模块,也可以通过http://github.e-sites.nl/zeptobuilder/进行在线自定义打包和压缩。

兼容Zepto的lazyload插件可以用这个https://github.com/jieyou/lazyload

Zepto modules

Zepto modules are individual files in the “src/” directory.

moduledefaultdescription
zeptoCore module; contains most methods
eventEvent handling via on() & off()
ajaxXMLHttpRequest and JSONP functionality
formSerialize & submit web forms
ieSupport for Internet Explorer 10+ on the desktop and Windows Phone 8
detectProvides $.os</code> and <code>$.browser information
fxThe animate() method
fx_methods Animated show, hide, toggle, and fade*() methods.
assets Experimental support for cleaning up iOS memory after removing image elements from the DOM.
data A full-blown data() method, capable of storing arbitrary objects in memory.
deferred Provides $.Deferred promises API. Depends on the “callbacks” module.
callbacks Provides $.Callbacks for use in “deferred” module.
selector Experimental jQuery CSS extensions support for functionality such as $('div:first') and el.is(':visible').
touch Fires tap– and swipe–related events on touch devices. This works with both `touch` (iOS, Android) and `pointer` events (Windows Phone).
gestureFires pinch gesture events on touch devices
stackProvides andSelf & end() chaining methods
ios3 String.prototype.trim and Array.prototype.reduce methods (if they are missing) for compatibility with iOS 3.x.
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

offbye

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值