基于JSON格式數(shù)據(jù)的簡單jQuery幻燈片插件(jquery-slider)
jquery-slider是一款基于JSON格式數(shù)據(jù)的jQuery幻燈片插件。該幻燈片通過JSON數(shù)據(jù)來提供圖片地址和描述信息等,你可以通過更換JSON數(shù)據(jù)來動態(tài)切換不同的圖片。
使用方法
在頁面中引入jquery和slider.js文件和font-awesome字體圖標文件。
<link rel='stylesheet' > <script type="text/javascript" src="js/jquery.min.js"></script> <script type="text/javascript" src="js/slider.js"></script>
HTML結(jié)構(gòu)
使用一個<div>作為幻燈片的容器,里面放置作為前后導航按鈕的<button>元素。
<div class="slider" id="slider"> <button type="button" class="button button-prev"> <i class="fa fa-chevron-left" aria-hidden="true"></i> </button> <button type="button" class="button button-next"> <i class="fa fa-chevron-right" aria-hidden="true"></i> </button> </div>
CSS樣式
為幻燈片設(shè)置下面的CSS樣式。
.slider { width: 100%; overflow: hidden; height: 500px; position: relative; } .sliderList { position: absolute; top: 0; width: 300%; height: 100%; list-style: none; } .sliderList li { position: absolute; top: 0; bottom: 0; overflow: hidden; width: 33.333333%; height: 100%; padding: 0; margin: 0; } .sliderList li img { width: 100%; min-height: 100%; border: none; } .bulletList { position: absolute; bottom: 15px; width: 100%; margin: 0 auto; list-style: none; } .bulletList li { display: inline-block; width: 12px; height: 12px; margin: 0 5px; -webkit-border-radius: 50%; -moz-border-radius: 50%; -ms-border-radius: 50%; border-radius: 50%; background-color: #fff; cursor: pointer; } .bulletList .bulletActive { background-color: #0b0d18; } .content { position: absolute; top: 0; left: 0; right: 0; background-color: rgba(0, 0, 0, 0.3); font-size: 48px; color: #fff; } .button { position: absolute; bottom: 15px; z-index: 2; display: block; width: 40px; height: 40px; box-sizing: border-box; margin: 0; padding: 0; border: none; -webkit-border-radius: 5px; -moz-border-radius: 5px; -ms-border-radius: 5px; border-radius: 5px; background-color: rgba(5, 0, 36, 0.6); color: #fff; } .button-prev { left: 15px; } .button-next { right: 15px; }
JSON數(shù)據(jù)
該幻燈片的圖片和圖片描述信息有JSON數(shù)據(jù)來提供,格式如下:
sliderJSON = [ { "imagePath": "1.jpg", "order": "2", "url": "#", "slideText": "圖片描述" }, { "imagePath": "2.jpg", "order": "3", "url": "#", "slideText": "圖片描述" }, { "imagePath": "3.jpg", "order": "1", "url": "#", "slideText": "圖片描述" }, { "imagePath": "4.jpg", "order": "4", "url": "#", "slideText": "圖片描述" }
jquery-slider幻燈片插件的github地址為:https://github.com/eryasov/jquery-slider
以上所述是小編給大家介紹的基于JSON格式數(shù)據(jù)的簡單jQuery幻燈片插件(jquery-slider),希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
相關(guān)文章
jQuery中serializeArray()與serialize()的區(qū)別實例分析
這篇文章主要介紹了jQuery中serializeArray()與serialize()的區(qū)別,結(jié)合實例形式分析了jQuery中serializeArray()與serialize()的具體功能、使用技巧與用法區(qū)別,需要的朋友可以參考下2015-12-12jQuery獲得document和window對象寬度和高度的方法
這篇文章主要介紹了jQuery獲得document和window對象寬度和高度的方法,涉及jQuery獲取document和window對象屬性的技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-03-03