<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                [TOC] # Zepto 框架 **Zepto** 是一個**輕量級**的針對現代高級瀏覽器的 **JavaScript 庫**, 它**與jquery 有著類似的api**。 如果你會用 jquery,那么你也會用 zepto。 **Zepto**的**設計目的是提供 jQuery 的類似的API**,但**并不是100%覆蓋 jQuery** 。Zepto設計的目的是有一個**5-10k**的通用庫、下載并快速執行、有一個熟悉通用的API,所以你能把你主要的精力放到應用開發上。 ## **jQuery和Zepto.js的區別** 1. **jQuery**更多是在**PC**端被應用,因此,考慮了很多**低級瀏覽器的的兼容性**問題;而**Zepto**.js則是直接**拋棄了低級瀏覽器的適配**問題,顯得很輕盈; 2. **Zepto**.js在**移動端**被運用的更加廣泛; 3. **jQuery**的底層是通過**DOM**來實現效果的, **zepto**.js 是用**css3** 來實現的; 4. **Zepto**.js可以說是**閹割**版本的**jQuery**。 ![](https://img.kancloud.cn/93/c2/93c29fe1811eb924371a131e57225a20_898x411.png) 5. **zepto**與**jquery**主要的區別是在**模塊**上的區別:[http://www.css88.com//doc//zeptojs\_api//](http://www.css88.com//doc//zeptojs_api//) * zepto默認只有**5個基本的模塊**,其他功能模塊需要**單獨引用** 。 * 引用的模塊,必須放在zepto的后面,`fx.js 和fx_methods.js`他們之間必須是fx\_methods.js在fx.js的后面;其他的包之間順序無所謂; * jQuery默認是一個文件中,**包含所有zepto中的功模塊**; * zepto的底層是通過**css3** 實現的,jQuery是操作的DOM,**所以**有些css3的效果,是jquery做不到的; * zepto比jQuery多了更多的**移動端**的 事件的支持,比如說**tap, swipe**…… * zepto的兼容性比jQuery差,因為zepto更多的是**注重移動端和效率**,jQuery注重的是**兼容性**。 > 注意:zepto上面的動畫,不要加太多, 因為動畫很耗性能,加多了會很卡,特別是一些webview開發; 英文版:[http://zeptojs.com//](http://zeptojs.com//) 中文版:[http://www.css88.com//doc//zeptojs\_api//](http://www.css88.com//doc//zeptojs_api//) github : [https://github.com/madrobby/zepto](https://github.com/madrobby/zepto) ## zepto兼容的瀏覽器 > Safari 6+ > Chrome 30+ > Firefox 24+ > iOS 5+ Safari > Android 2.3+ Browser > Internet Explorer 10+ ## Zepto初體驗 ``` <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style> div{ width: 200px; height: 200px; background-color: red; } </style> </head> <body> <button id="btn">點擊改顏色</button> <div class="box"></div> <!--引入jq--> <!--<script src="js/jquery-3.2.0.js"></script>--> <!--引入zepto--> <script src="js/zepto.min.js"></script> <script> $(function () { $('#btn').on('click',function () { $('.box').css({ backgroundColor:'green', }); }); }) </script> </body> </html> ``` ## zepto與jquery使用上的區別 注意:**zepto**與**jquery**主要的區別是在**模塊**上的區別:[http://www.css88.com//doc//zeptojs\_api//](http://www.css88.com//doc//zeptojs_api//) ### 1.選擇器-模塊 選擇器$( ' div:eq(1) ' ) : [http://www.w3school.com.cn/jquery/jquery\_ref\_selectors.asp](http://www.w3school.com.cn/jquery/jquery_ref_selectors.asp) 閉包的好處:[http://blog.csdn.net/vuturn/article/details/43055279](http://blog.csdn.net/vuturn/article/details/43055279) 例子:點擊改第二個顏色 ``` <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style> div{ width: 200px; height: 200px; background-color: red; margin: 10px; } </style> </head> <body> <button id="btn">點擊改第二個顏色</button> <div >1</div> <div >2</div> <!--引入jq--> <!--<script src="js/jquery-3.2.0.js"></script>--> <!--引入zepto--> <script src="js/zepto.min.js"></script> <!--selector要放在zepto后面--> <script src="js/selector.js"></script> <script> $(function () { /*點擊改第二個顏色*/ $('#btn').on('click',function () { $('div:eq(1)').css({ backgroundColor:'green', }); }); }); </script> </body> </html> ``` ### 2.動畫-模塊-animate 例子:點擊改變寬度 ``` ~~~ <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>03-zepto動畫</title> <style> div { width: 200px; height: 200px; background: skyblue; } </style> <!--<script src="js/jquery-1.7.2.min.js"></script>--> <script src="js/zepto.js"></script> <script src="js/fx.js"></script> </head> <body> <button>d點擊</button> <div></div> <script> $(function () { $('button').click(function () { $('div').animate({width: 400, background: 'gold'}, 5000); // $('div').animate({background:'gold'},5000); }); }) </script> </body> </html> ~~~ ``` ### 3.隱藏toggle-模塊 ``` ~~~ <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <title>Title</title> <style> div { width: 200px; height: 200px; background-color: red; } </style> </head> <body> <button id="btn">來回切換隱藏</button> <div class="box"></div> <!--<script src="js/jquery-3.2.0.js"></script>--> <script src="js/zepto.min.js"></script> <script src="js/fx.js"></script> <script src="js/fx_methods.js"></script> <script> $(function () { $('#btn').on('click', function () { $('.box').toggle(1000); }) }) </script> </body> </html> ~~~ ``` ### 4.Tap事件-模塊 **tap** `只作用在移動端,PC端是無效的;` **click** 在pc端和移動端都是ok的; 但是我們在移動端要用tap,因為 tap 比 click 快200-300ms。 例子,點擊改變顏色: ``` ~~~ <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <title>Title</title> <style> div { width: 200px; height: 200px; background-color: red; } </style> </head> <body> <button id="btn">點擊修改顏色</button> <div class="box"></div> <!--<script src="js/jquery-3.2.0.js"></script>--> <script src="js/zepto.min.js"></script> <script src="js/touch.js"></script> <script> $(function () { /*$('#btn').on('click', function () { $('.box').css({ backgroundColor: 'green', }); });*/ $('#btn').tap(function () { $('.box').css({ backgroundColor:'green', }) }); }); </script> </body> </html> ~~~ ``` ### 5.swipe滑動-模塊-animate 注意: 如果想在移動設備上使用swipe事件,先要**清除系統默認的手勢事件:touch-action: none**,如果沒有清楚系統默認的事件可能swiper事件不會回調和tap事件觸發多次。 ``` <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <title>Title</title> <style> div{ width: 100px; height: 100px; background-color: red; position: absolute; left: 30px; top: 30px; } /*清楚系統默認的事件*/ *{ touch-action: none; } </style> </head> <body> <div class="box"></div> <script src="js/zepto.min.js"></script> <script src="js/touch.js"></script> <script src="js/fx.js"></script> <script> $(function () { /** * $('.box').swipe(function () { console.log('滑動了') }); $('.box').swipeLeft(function () { console.log('向左滑動了') }); $('.box').swipeRight(function () { console.log('向右滑動了') }); $('.box').swipeUp(function () { console.log('向上滑動了') }); $('.box').swipeDown(function () { console.log('向下滑動了') }); */ $('.box').swipeLeft(function () { $(this).animate({ left:0, }) }); $('.box').swipeRight(function () { $(this).animate({ left:'200px', }) }); $('.box').swipeUp(function () { $(this).animate({ top:0, }) }); $('.box').swipeDown(function () { $(this).animate({ top:'200px', }) }); }) </script> </body> </html> ``` # Zepto實現tab效果am ## 1.新建一個項目 ~~~ <!--引入zepto--> <script src="js/zepto.min.js"></script> <!--引入touch--> <script src="js/touch.js"></script> ~~~ ![](https://img.kancloud.cn/4b/34/4b3457a8530860c375281a16305a8ced_1119x623.png) ## 2.搭建布局 ![](https://img.kancloud.cn/ac/82/ac82d6202136ace8884c5a6ce77bfa6c_1149x680.png) ~~~ <!DOCTYPE html> <html lang="en"> <head> ? ?<meta charset="UTF-8"> ? ?<!-- ? ? ? ?視口:兼容移動 ? ?--> ? ?<meta name="viewport" ? ? ? ? ?content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> ? ?<!-- ? ? ? ?告訴ie瀏覽器使用最新的解析器解析 ? ?--> ? ?<meta http-equiv="X-UA-Compatible" content="IE=edge"> ? ?<title>Title</title> </head> <body> ? ?<div class="box"> ? ? ? ?<!--頭部--> ? ? ? ?<ul class="header"> ? ? ? ? ? ?<li class="current">新聞</li> ? ? ? ? ? ?<li>科技</li> ? ? ? ?</ul> ? ? ? ? ?<!--線條--> ? ? ? ?<span class="line"></span> ? ? ? ? ?<!--內容--> ? ? ? ?<div class="list"> ? ? ? ? ? ?<div class="list1"> ? ? ? ? ? ? ? ?<ul> ? ? ? ? ? ? ? ? ? ?<li>新聞內容新聞內容</li> ? ? ? ? ? ? ? ? ? ?<li>新聞內容新聞內容</li> ? ? ? ? ? ? ? ? ? ?<li>新聞內容新聞內容</li> ? ? ? ? ? ? ? ? ? ?<li>新聞內容新聞內容</li> ? ? ? ? ? ? ? ? ? ?<li>新聞內容新聞內容</li> ? ? ? ? ? ? ? ? ? ?<li>新聞內容新聞內容</li> ? ? ? ? ? ? ? ?</ul> ? ? ? ? ? ? ? ?<a href="javascript:;">查看更多...</a> ? ? ? ? ? ?</div> ? ? ? ? ? ?<div class="list2"> ? ? ? ? ? ? ? ?<ul> ? ? ? ? ? ? ? ? ? ?<li>科技內容新聞內容</li> ? ? ? ? ? ? ? ? ? ?<li>科技內容新聞內容</li> ? ? ? ? ? ? ? ? ? ?<li>科技內容新聞內容</li> ? ? ? ? ? ? ? ? ? ?<li>科技內容新聞內容</li> ? ? ? ? ? ? ? ? ? ?<li>科技內容新聞內容</li> ? ? ? ? ? ? ? ? ? ?<li>科技內容新聞內容</li> ? ? ? ? ? ? ? ?</ul> ? ? ? ? ? ? ? ?<a href="javascript:;">查看更多...</a> ? ? ? ? ? ?</div> ? ? ? ?</div> ? ?</div> <!--引入zepto--> <script src="js/zepto.min.js"></script> <!--引入touch--> <script src="js/touch.js"></script> </body> </html> ~~~ 執行的效果: ![](https://img.kancloud.cn/b3/21/b321f07f2007d6eae7286c0b353f50e6_527x552.png) ## 3.添加默認的樣式 ~~~ *{ ? ? ? ? ? ..... ? ? ? ? ? ?/*清除系統的觸摸事件*/ ? ? ? ? ? ?touch-action: none; ? ? ? ? ? ?/*盒子大小的計算方式*/ ? ? ? ? ? ?/*box-sizing: border-box;*/ ? ? ? } ? ? ? ?/*box里面的盒子要移動,移動要用到定位*/ ? ? ? ?.box{ ? ? ? ? ? ?position: relative; ? ? ? } ~~~ ![](https://img.kancloud.cn/f3/b5/f3b59acee7ddd7bff42cadbc8fb9c20a_1022x599.png) ## 4.頭部的樣式-40-16 ![](https://img.kancloud.cn/76/fe/76fe1cbe7fe241900669e3454822330a_998x646.png) ![](https://img.kancloud.cn/17/e6/17e64134ddd8216153c1c698866cf481_378x379.png) ## 5.線條樣式-37-3 > 線條span通過定位來改變標簽類型,不然寬高不起作用 ![](https://img.kancloud.cn/36/97/3697f2986e0330469f7568945831d9cb_1244x630.png) ## 6.內容樣式 1.list 整個列表的樣式 ![](https://img.kancloud.cn/96/d7/96d777c6c26448ffa5e102ab9ce41e65_1329x646.png) 2.列表中ul 和 li的樣式 ![](https://img.kancloud.cn/03/9e/039e3bc25084a64f8039f678fe04cb05_1273x630.png) 3.查看更多a標簽樣式 ![](https://img.kancloud.cn/bf/28/bf28fa8115dd65247f463fd17234749f_1292x656.png) ## 7.點擊實現切換-tap ### 1.監聽頭部的點擊事件 ~~~ $(function () { ? ? ? //1.頭部的點擊事件 ? ? ? $('.header li').tap(function () { ? ? ? ? ? //2.拿到點擊的索引 ? ? ? ? ? ?var index=$(this).index(); ? ? ? ? ? ?alert(index); ? ? ? }); ? }) ~~~ ![](https://img.kancloud.cn/e9/8c/e98c9830c815de0728a16fd90c1ddf82_1051x620.png) ### 2.點擊實現切換-css #### 1.文字的切換 ~~~ ? $(function () { ? ? ? ?//1.頭部的點擊事件 ? ? ? ?$('.header li').tap(function () { ? ? ? ? ? ?//2.拿到點擊的索引 ? ? ? ? ? ?var index=$(this).index(); // ? ? ? ? ? alert(index); ? ? ? ? ? ? ?$(this).addClass('current') ? ? ? ? ? ? ? ?/*同級節點,清除樣式*/ ? ? ? ? ? ? ? .siblings().removeClass('current'); ? ? ? }); ? }) ~~~ ![](https://img.kancloud.cn/de/03/de0300612d28ddae00162c550ca79947_1133x604.png) #### 2.線條的移動 ~~~ $('.line').css({ ? ? ? ? ? ? ? ?transform:'translateX('+ index * 100 +'%)', ?// 相對自身移動100% ? ? ? ? ? ? ? ?transition:'all 0.35s linear', }) ~~~ ![](https://img.kancloud.cn/d7/4b/d74baad4e0e83d53305bd37a53994cc9_1237x653.png) 3.內容的移動 ~~~ $('.list').css({ ? ? ? ? ? ? ? ?transform:'translateX('+ -index * 50 +'%)', ? // 相對自身移動50% ? ? ? ? ? ? ? ?transition:'all 0.35s linear', }) ~~~ ![](https://img.kancloud.cn/6f/4c/6f4ce04fc29c532b7487b56705764045_1256x636.png) ## 8.滑動實現切換 ### 1.監聽左滑動和右滑 ![](https://img.kancloud.cn/13/aa/13aa9b8b7ae029f4c5bc1cb31384dbcb_1078x580.png) ### 2.處理左滑-css ![](https://img.kancloud.cn/ba/15/ba15219158a416b334badd3684839a1f_1153x621.png) ~~~ ? ? ? ?//2.監聽頁面的滑動 ? ? ? ?$('.list').swipeLeft(function () { ? ? ? ? ? ?//2.拿到點擊的索引 ? ? ? ? ? ?var index=1; // ? ? ? ? ? alert(index); ? ? ? ? ? ?//3.文字改色 ? ? ? ? ? ?$('.header li').eq(index).addClass('current') ? ? ? ? ? ? ? ?/*同級節點,清除樣式*/ ? ? ? ? ? ? ? .siblings().removeClass('current'); ? ? ? ? ? ?//4.線條移動 ? ? ? ? ? ?$('.line').css({ ? ? ? ? ? ? ? ?transform:'translateX('+ index * 100 +'%)', ? ? ? ? ? ? ? ?transition:'all 0.35 linear', ? ? ? ? ? }) ? ? ? ? ? ? ?//5.內容移動 ? ? ? ? ? ?$('.list').css({ ? ? ? ? ? ? ? ?transform:'translateX('+ -index * 50 +'%)', ? ? ? ? ? ? ? ?transition:'all 0.35 linear', ? ? ? ? ? }) ? ? ? }) ~~~ ### 5.處理右滑-css ![](https://img.kancloud.cn/24/9b/249bca4e1a71742ab2b15e69cafd913c_1179x643.png)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看