Zepto和Jquery區別

來源:互聯網
上載者:User

標籤:cte   移動端   事件對象   call   隱藏   函數   turn   font   isa   

---恢複內容開始---

《zepto移動端事件》


1、$("#xx").tap(function(){ //tap在螢幕點擊時觸發
    alert("sssss");
})

2、$("div").singleTap(function(){ //singleTap在螢幕單擊時觸發
    alert("單擊");
})

3、$("div").doubleTap(function(){ //doubleTap在螢幕雙擊時觸發
    alert("雙擊");
})

4、$("div").longTap(function(){ //longTap長按螢幕時觸發
    alert("摁住");
})

5、$("div").swipe(function(){ //swipe滑動時觸發
    alert("滑動") 

})

可選方向:

  1、swipeUp 向上滑動 2、swipeDown 向下滑動

  2、swipeLeft 向左滑動 3、swipeRight 向右滑動

《Zepto和Jquery的區別》

 

 

1. Zepto 對象 不能自訂事件
例如執行: $({}).bind(‘cust‘, function(){});
結果: TypeError: Object has no method ‘addEventListener‘
解決辦法是建立一個脫離文檔流的節點作為事件對象:
例如: $(‘‘).bind(‘cust‘, function(){});

2. Zepto 的選取器運算式: [name=value] 中value 必須用 雙引號 " or 單引號 ‘ 括起來
例如執行:$(‘[data-userid=123123123]‘)
結果:Error: SyntaxError: DOM Exception 12
解決辦法: $(‘[data-userid="123123123]"‘) or $("[data-userid=‘123123123‘]")

2-1.zepto的選取器沒有辦法選出 $("div[name!=‘abc‘]") 的元素

 

2-2.zepto擷取select元素的選中option不能用類似jq的方法$(‘option[selected]‘),因為selected屬性不是css的標準屬性
應該使用$(‘option‘).not(function(){ return !this.selected })
比如:jq:$this.find(‘option[selected]‘).attr(‘data-v‘) * 1
zepto:$this.find(‘option‘).not(function() {return !this.selected}).attr(‘data-v‘) * 1
但是擷取有select中含有disabled屬性的元素可以用 $this.find("option:not(:disabled)") 因為disabled是標準屬性

2-3、zepto在操作dom的selected和checked屬性時盡量使用prop方法

3.Zepto 是根據標準瀏覽器寫的,所以對於節點尺寸的方法只提供 width() 和 height(),省去了 innerWidth(), innerHeight(),outerWidth(),outerHeight()
Zepto.js: 由盒模型( box-sizing )決定
jQery: 忽略盒模型,始終返回內容地區的寬/高(不包含 padding 、 border )解決方式就是使用 .css(‘width‘) 而不是 .width() 。

3-2.offset()
Zepto.js: 返回 top 、 left 、 width 、 height
jQuery: 返回 width 、 height

3-3.隱藏元素
Zepto.js: 無法擷取寬高;
jQuery: 可以擷取。

4.Zepto 的each 方法只能遍曆 數組,不能遍曆JSON對象

5.Zepto 的animate 方法參數說明 :詳情點擊->
zepto中animate的用法

6.zepto的jsonp callback函數名無法自訂

---恢複內容結束---

Zepto和Jquery區別

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.