最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

jQuery實現(xiàn)輪播圖源碼

 更新時間:2019年10月23日 10:22:08   作者:baobao267  
這篇文章主要為大家詳細介紹了jQuery實現(xiàn)輪播圖源碼,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了jQuery實現(xiàn)輪播圖展示的具體代碼,供大家參考,具體內(nèi)容如下

設計:

根據(jù)上圖可以看出,輪播圖需要以下元素:外面的盒子div、放置圖片集合的盒子ul、放置兩側(cè)按鈕的盒子div、下側(cè)順序按鈕div

源代碼如下:

一、html源碼如下:

<div class="outer">
 
 <ul class="img">
 <li><a><img src="../static/img/1.jpg"></a></li>
 <li><a><img src="../static/img/2.jpg"></a></li>
 <li><a><img src="../static/img/3.jpg"></a></li>
 <li><a><img src="../static/img/4.jpg"></a></li>
 </ul>
 
 
 <ul class="num">
 <li class="current">1</li>
 <li>2</li>
 <li>3</li>
 <li>4</li>
 </ul>
 
 <div class="left_btn btn"><</div>
 <div class="right_btn btn">></div>
</div>

二、css樣式實現(xiàn):

<style>
 /*去掉默認瀏覽器樣式*/
 *{
 margin: 0;
 padding: 0;
 }
 /*去掉li標簽默認樣式*/
 li{
 list-style: none;
 }
 /*最外層盒子樣式處理:
 1.設置與輪播圖高寬一致
 2.設置縱向距頂部50px,水平居中
 3.設置自己為固定位置
 */
 .outer{
 height: 470px;
 width: 590px;
 margin: 50px auto;
 position:relative;
 }
 /*輪播圖片集合處理:
 1.將其設置為脫離文檔流
 2.設置距頂部和左側(cè)都為0
 */
 .img li{
 position: absolute;
 top: 0;
 left: 0;
 }
 /*順序按鈕區(qū)域處理:
 1.設置脫離文檔流
 2.通過設置text-align、width使其整體水平居中
 3.設置距離底部20px
 */
 .num{
 position: absolute;
 text-align: center;
 width: 100%;
 bottom: 20px;
 }
 /*順序按鈕處理:
 1.將其設置為行級及塊級兼容顯示
 2.設置其寬高
 3.設置背景色及字體顏色
 4.設置字體水平居中
 5.通過設置line-height與height一致,使其字體縱向居中
 6.設置其樣式為圓形
 7.增加按鈕左右間距
 */
 .num li{
 display: inline-block;
 width: 20px;
 height: 20px;
 background-color: darkgray;
 color: white;
 text-align: center;
 line-height: 20px;
 border-radius: 50%;
 margin: 0 20px;
 }
 /*左、右按鈕相同部分處理:
 1.設置其脫離文檔流
 2.設置其寬高
 3.設置背景色及字體顏色
 4.設置字體水平居中
 5.通過設置line-height與height一致,使其字體縱向居中
 6.通過設置top、margin-top使其整體縱向居中
 7.默認不顯示
 */
 .btn{
 position: absolute;
 width: 20px;
 height: 50px;
 background-color: darkgray;
 color: white;
 text-align: center;
 line-height: 50px;
 top: 50%;
 margin-top: -25px;
 display: none;
 }
 /*左側(cè)按鈕處理:
 設置左側(cè)為0
 */
 .left_btn{
 left: 0;
 }
 /*右側(cè)按鈕處理:
 設置右側(cè)為0
 */
 .right_btn{
 right: 0;
 }
 /*鼠標懸浮至輪播圖區(qū)域時左、右按鈕處理:
 1.設置左右按鈕顯示樣式為行級塊級兼容
 2.設置鼠標放置在左右按鈕時樣式為小手
 */
 .outer:hover .btn{
 display: inline-block;
 cursor: pointer;
 }
 /*設置順序按鈕初始按鈕樣式:
 設置為紅色(由于樣式級別問題會導致設置無效,可通過兩種方式解決:
 1.后面加上!important
 2.將css定位寫詳細,比如:.outer .num .current{……
 )
 */
 .current{
 background-color: red!important;
 }
 
</style>

三、JQuery實現(xiàn):

<script src="../static/jquery-3.3.1.min.js"></script>
<script>
 /*定義位置:由于圖片個數(shù)與下側(cè)順序按鈕數(shù)量一致,可通過位置進行關聯(lián)*/
 var index=0;
 /*當鼠標放到順序按鈕上時:
 1.將當前這個順序按鈕增加樣式為紅色背景
 2.移除周圍其他同級元素紅色背景樣式
 3.獲取當前順序按鈕的index
 4.通過index獲取該位置圖片
 5.一秒鐘漸入該圖片
 6.一秒鐘漸出其他相鄰圖片
 7.防止移動過快導致的效果閃現(xiàn),使用stop方法
 */
 $(".num li").mousemove(function () {
  $(this).addClass("current").siblings().removeClass("current");
  index=$(this).index();
  $(".img li").eq(index).stop().fadeIn(1000).siblings().stop().fadeOut(1000);
 });
 /*設置每一秒鐘自動輪播:
 1.獲取當前位置序號:自加操作;當超過圖片最大序號時序號設置為0
 2.設置下側(cè)順序按鈕及輪播圖顯示
 */
 var time=setInterval(move,1000);
 function move() {
 index++;
 if (index==4){
  index=0
 }
 $(".num li").eq(index).addClass("current").siblings().removeClass("current");
 $(".img li").eq(index).stop().fadeIn(1000).siblings().stop().fadeOut(1000);
 };
 /*當鼠標劃入、劃出輪播圖區(qū)域時:
 1.劃入時停止自動輪播
 2.劃出時繼續(xù)自動輪播
 */
 $(".outer").hover(function () {
 clearInterval(time);
 },
 function () {
 time=setInterval(move,1000);
 });
 /*點擊右側(cè)按鈕時執(zhí)行*/
 $(".right_btn").click(function () {
 move();
 });
 /*點擊左側(cè)按鈕時執(zhí)行*/
 function moveL() {
  index--;
 if (index==-1){
  index=3
 }
 $(".num li").eq(index).addClass("current").siblings().removeClass("current");
 $(".img li").eq(index).stop().fadeIn(1000).siblings().stop().fadeOut(1000);
 }
 $(".left_btn").click(function () {
 moveL();
 });
</script>

完整源碼下載:jQuery輪播圖源碼

更多關于輪播圖效果的專題,請點擊下方鏈接查看學習

javascript圖片輪播效果匯總

jquery圖片輪播效果匯總

Bootstrap輪播特效匯總

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

最新評論

新蔡县| 黑河市| 九龙坡区| 乾安县| 通渭县| 北海市| 汉寿县| 曲沃县| 吉隆县| 江西省| 石棉县| 三明市| 泾源县| 望奎县| 青川县| 塔城市| 铁力市| 嘉黎县| 壶关县| 东安县| 龙陵县| 丰原市| 沙河市| 福泉市| 涿鹿县| 湖北省| 宾阳县| 香格里拉县| 麻江县| 保德县| 文成县| 桃江县| 武穴市| 汝城县| 绵阳市| 南岸区| 资兴市| 许昌市| 乐平市| 苏尼特右旗| 乐山市|