您好,登錄后才能下訂單哦!
小編給大家分享一下Swiper.js如何實(shí)現(xiàn)移動(dòng)端元素左右滑動(dòng),相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
swiper.js也是一個(gè)很好用的移動(dòng)端的js庫(kù)。
需要引入它的css文件和js文件。用法很簡(jiǎn)單,加入相應(yīng)的類(lèi)即可,看一下Demo,很容易看懂。
我的例子如下:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Swiper demo</title> <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1"> <!-- Link Swiper's CSS --> <link rel="stylesheet" href="css/swiper.min.css" > <!-- Demo styles --> <style> body { background: #eee; font-family: Helvetica Neue, Helvetica, Arial, sans-serif; font-size: 14px; color:#000; margin: 0; padding: 0; } .swiper-container { width: 100%; height: 300px; margin: 20px auto; } .swiper-slide { text-align: center; font-size: 18px; background: #fff; } </style> </head> <body> <!-- Swiper --> <div class="swiper-container"> <div class="swiper-wrapper"> <div class="swiper-slide">Slide 1</div> <div class="swiper-slide">Slide 2</div> <div class="swiper-slide">Slide 3</div> <div class="swiper-slide">Slide 4</div> <div class="swiper-slide">Slide 5</div> <div class="swiper-slide">Slide 6</div> <div class="swiper-slide">Slide 7</div> <div class="swiper-slide">Slide 8</div> <div class="swiper-slide">Slide 9</div> <div class="swiper-slide">Slide 10</div> </div> </div> <div id="bless"> <input id="bless-word" type="text"></input> <a id="share-button">立即分享</a> </div> <!-- Swiper JS --> <script src="js/swiper.min.js"></script> <script type="text/javascript" src="js/jquery-2.2.0.js"></script> <!-- Initialize Swiper --> <script> var swiper = new Swiper('.swiper-container', { slidesPerView: 3, paginationClickable: true, spaceBetween: 30, freeMode: true }); var shareBtn = document.getElementById("share-button"); var bless = document.getElementById("bless-word"); shareBtn.addEventListener("click",function(){ var blessWord = bless.value; var url = "index2.html?word=" + blessWord; shareBtn.setAttribute("href",url); },false); </script> </body> </html>
以上是“Swiper.js如何實(shí)現(xiàn)移動(dòng)端元素左右滑動(dòng)”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。