jQuery實現(xiàn)圖片向左向右切換效果的簡單實例
jQuery實現(xiàn)圖片向左向右切換效果的簡單實例
<div class="imageRotation container"> <div class="imageBox"> <img src="images/chugui.jpg"> <img src="images/ad_auto.jpg"> <img src="images/ad_home.jpg"> <img src="images/ad_nba.jpg"> <img src="images/ad_stock.jpg"> <img src="images/ad_yuetu.jpg"> </div> <div class="iconBox"> <span rel="1" class="active">1</span> <span rel="2">2</span> <span rel="3">3</span> <span rel="4">4</span> <span rel="5">5</span> <span rel="6">6</span> </div> </div> //CSS樣式 .container { width: 1000px; margin: 0 auto; } .imageRotation { width: 1000px; height: 480px; position: relative; overflow: hidden; margin-top: 8px; } .imageBox { position: absolute; overflow: hidden; display: block; height: 480px; } .imageBox img { width: 1000px; height: 480px; float: left; border: none; display: block; } .iconBox { position: absolute; width: 120px; height: 12px; line-height: 12px; top: 444px; right: 20px; text-align: center; } .iconBox span { width: 6px; height: 6px; border-radius: 10px; text-align: center; background: #555; border: 2px solid #f5f5f5; float: left; text-indent: -999em; margin-left: 5px; cursor: pointer; } .iconBox span.active { width: 6px; height: 6px; background: #820000; border-radius: 10px; text-align: center; text-indent: -999em; } //js邏輯 $(function() { $(".imageRotation").each(function() { var imageRotation = this, imageBox = $(imageRotation).children(".imageBox"), iconBox = $(imageRotation).children(".iconBox"), iconArr = $(iconBox).children(), imageWidth = $(imageRotation).width(), imageNum = $(imageBox).children().size(), imageRollWidth = imageWidth * imageNum, activeID = parseInt($($(iconBox).children(".active")).attr("rel")), nextID = 0; var setIntervalID, setIntervalTime = 3000, speed = 500; //設(shè)置 圖片容器 的寬度 $(imageBox).css({ 'width': imageRollWidth + "px" }); //圖片切換函數(shù) function imageRoll(clickID) { if (clickID) { nextID = clickID; } else { if (activeID <= 5) { nextID = activeID + 1 } else { nextID = 1; } } //圖標添加樣式、刪除樣式 $(iconArr[activeID - 1]).removeClass("active"); $(iconArr[nextID - 1]).addClass("active"); $(imageBox).animate({ left: "-" + (nextID - 1) * imageWidth + "px" }, speed); activeID = nextID; } setIntervalID = setInterval(imageRoll, setIntervalTime); //鼠標移動事件 $(imageBox).hover(function() { clearInterval(setIntervalID); }, function() { setIntervalID = setInterval(imageRoll, setIntervalTime); }); //鼠標點擊事件 $(iconArr).click(function() { clearInterval(setIntervalID); var clickID = parseInt($(this).attr("rel")); //獲取當前點擊圖片的id imageRoll(clickID); setIntervalID = setInterval(imageRoll, setIntervalTime); }); }); });
以上這篇jQuery實現(xiàn)圖片向左向右切換效果的簡單實例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
ASP.NET jQuery 實例9 通過控件hyperlink實現(xiàn)返回頂部效果
ASP.NET jQuery 實例9 通過控件hyperlink實現(xiàn)返回頂部效果的實現(xiàn)代碼,需要的朋友可以參考下2012-02-02jQuery+Ajax請求本地數(shù)據(jù)加載商品列表頁并跳轉(zhuǎn)詳情頁的實現(xiàn)方法
本文通過實例代碼給大家介紹了jQuery+Ajax請求本地數(shù)據(jù)加載商品列表頁并跳轉(zhuǎn)詳情頁,需要的朋友可以參考下2017-07-07基于jquery的9行js輕松實現(xiàn)tab控件示例
tab控件的實現(xiàn)方法有很多,在本文為大家詳細介紹下如何通過9行js實現(xiàn)簡單的tab控件,感興趣的朋友不要錯過2013-10-10jquery validate poshytip 自定義樣式
項目中做了一個jquery.validate氣泡提示在新版的jquery.validate中,有這個功能,但在我這里不怎么好用,所以自己加了一個,找了一些插件qtip2的樣式不錯,需要的朋友可以參考下2012-11-11jQuery實現(xiàn)數(shù)字自動增加或者減少的動畫效果示例
這篇文章主要介紹了jQuery實現(xiàn)數(shù)字自動增加或者減少的動畫效果,涉及jQuery結(jié)合時間函數(shù)動態(tài)設(shè)置元素屬性相關(guān)操作技巧,需要的朋友可以參考下2018-12-12淺析jQuery Ajax請求參數(shù)和返回數(shù)據(jù)的處理
這篇文章主要介紹了淺析jQuery Ajax請求參數(shù)和返回數(shù)據(jù)的處理的相關(guān)資料,需要的朋友可以參考下2016-02-02