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

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

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

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

設(shè)計(jì):

根據(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樣式實(shí)現(xiàn):

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

三、JQuery實(shí)現(xiàn):

<script src="../static/jquery-3.3.1.min.js"></script>
<script>
 /*定義位置:由于圖片個(gè)數(shù)與下側(cè)順序按鈕數(shù)量一致,可通過(guò)位置進(jìn)行關(guān)聯(lián)*/
 var index=0;
 /*當(dāng)鼠標(biāo)放到順序按鈕上時(shí):
 1.將當(dāng)前這個(gè)順序按鈕增加樣式為紅色背景
 2.移除周?chē)渌?jí)元素紅色背景樣式
 3.獲取當(dāng)前順序按鈕的index
 4.通過(guò)index獲取該位置圖片
 5.一秒鐘漸入該圖片
 6.一秒鐘漸出其他相鄰圖片
 7.防止移動(dòng)過(guò)快導(dǎo)致的效果閃現(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);
 });
 /*設(shè)置每一秒鐘自動(dòng)輪播:
 1.獲取當(dāng)前位置序號(hào):自加操作;當(dāng)超過(guò)圖片最大序號(hào)時(shí)序號(hào)設(shè)置為0
 2.設(shè)置下側(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);
 };
 /*當(dāng)鼠標(biāo)劃入、劃出輪播圖區(qū)域時(shí):
 1.劃入時(shí)停止自動(dòng)輪播
 2.劃出時(shí)繼續(xù)自動(dòng)輪播
 */
 $(".outer").hover(function () {
 clearInterval(time);
 },
 function () {
 time=setInterval(move,1000);
 });
 /*點(diǎn)擊右側(cè)按鈕時(shí)執(zhí)行*/
 $(".right_btn").click(function () {
 move();
 });
 /*點(diǎn)擊左側(cè)按鈕時(shí)執(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輪播圖源碼

更多關(guān)于輪播圖效果的專(zhuān)題,請(qǐng)點(diǎn)擊下方鏈接查看學(xué)習(xí)

javascript圖片輪播效果匯總

jquery圖片輪播效果匯總

Bootstrap輪播特效匯總

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

镶黄旗| 来安县| 高州市| 沁阳市| 东平县| 丰都县| 吐鲁番市| 伊金霍洛旗| 永寿县| 阿图什市| 河西区| 两当县| 越西县| 台前县| 同德县| 波密县| 隆昌县| 睢宁县| 贵阳市| 凤城市| 永顺县| 高阳县| 江西省| 江川县| 九江市| 克东县| 皋兰县| 宁海县| 崇州市| 贵阳市| 桂平市| 两当县| 班玛县| 黔南| 克东县| 咸丰县| 龙山县| 平乐县| 汝城县| 汉源县| 龙川县|