JS+css3實(shí)現(xiàn)幻燈片輪播圖
更新時間:2020年08月14日 15:36:11 作者:littleboyck
這篇文章主要為大家詳細(xì)介紹了JS+css3實(shí)現(xiàn)幻燈片輪播圖,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實(shí)例為大家分享了JS+css3實(shí)現(xiàn)幻燈片輪播圖的具體代碼,供大家參考,具體內(nèi)容如下
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <style> *{ margin: 0; padding: 0; -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; } .clearfix:after{ clear: both; } .clearfix:after,.clearfix:before{ content: ""; display: table; } .slide_view{ width: 600px; height: 200px; overflow: hidden; margin: 40px auto; position: relative; } ul{ width: 600px; height: 100%; } li{ position: absolute; width: 600px; height:100%; opacity: 0; } li.active{ opacity: 1; } .hor-slide-ani .next-out { animation: hor-slide-next-out .8s forwards cubic-bezier(0.7, 0, 0.3, 1); } .hor-slide-ani .next-in{ animation: hor-slide-next-in .8s forwards cubic-bezier(0.7, 0, 0.3, 1); } .hor-slide-ani .prev-out { animation: hor-slide-prev-out .8s forwards cubic-bezier(0.7, 0, 0.3, 1); } .hor-slide-ani .prev-in{ animation: hor-slide-prev-in .8s forwards cubic-bezier(0.7, 0, 0.3, 1); } @keyframes hor-slide-next-out{ from{ opacity: 1; } to{ opacity: 1; transform: translateX(100%); } } @keyframes hor-slide-next-in{ from{ opacity: 1; transform: translateX(-100%); } to{ opacity: 1; transform: translateX(0); } } @keyframes hor-slide-prev-out{ from{ opacity: 1; } to{ opacity: 1; transform: translateX(-100%); } } @keyframes hor-slide-prev-in{ from{ opacity: 1; transform: translateX(100%); } to{ opacity: 1; transform: translateX(0); } } .prev{ position: absolute; left: 10px; top: 40%; display: block; padding: 10px; text-align: center; width: 20px; height: 20px; border-radius: 100%; background: rgba(0,0,0,.4); color: white; font-size: 22px; line-height: 22px; } .next{ position: absolute; right: 10px; top: 40%; display: block; padding: 10px; text-align: center; width: 20px; height: 20px; border-radius: 100%; background: rgba(0,0,0,.4); color: white; font-size: 22px; line-height: 22px; } </style> </head> <body> <div class="slide_view"> <ul class="slides clearfix hor-slide-ani" style="position: relative;"> <li class="active" style="background: salmon;">1</li> <li style="background: darkcyan;">2</li> <li style="background: seagreen;">3</li> <li style="background: sandybrown;">4</li> </ul> <div class="control"> <span class="prev">←</span> <span class="next">→</span> </div> </div> </body>
<script type="text/javascript" src="js/jquery-2.1.4.min.js" ></script> <script> var aniName = (function(el) { var animations = { animation: 'animationend', OAnimation: 'oAnimationEnd', MozAnimation: 'mozAnimationEnd', WebkitAnimation: 'webkitAnimationEnd', }; for (var t in animations) { if (el.style[t] !== undefined) { return animations[t]; } } return false; })(document.createElement('div')); var aniEndCallback=function($ele,endCall){ if(aniName && typeof endCall == 'function'){ var called=false; //在每次transitionEnd的事件后執(zhí)行該函數(shù) var callback = function(){ if (!called){ called=true; endCall($ele); } }; $ele[0].addEventListener(aniName,function(){ callback(); //通過setTimeout來補(bǔ)救windowphone中不觸發(fā)事件的問題 setTimeout(callback,200); },false); }else{ endCall($ele); } }; $(function(){ var aniStatus = false; $('.next').click(function(){ if(aniStatus){return}; aniStatus = true; var $slides = $('.slides').children() , slideCount = $slides.length , $active = $('.active') , curActiveIndex = $('.active').index() , nextActiveIndex = curActiveIndex -1; if(curActiveIndex == 0){ nextActiveIndex = slideCount-1; } $slides.eq(curActiveIndex).addClass('next-out'); $slides.eq(nextActiveIndex).addClass('next-in'); aniEndCallback($active,function($ele){ aniStatus = false; $active.removeClass('next-out active'); $slides.eq(nextActiveIndex).removeClass('next-in').addClass('active'); }); }); $('.prev').click(function(){ if(aniStatus){return;}//不在動畫狀態(tài),才能執(zhí)行 aniStatus= true; var $slides = $('.slides').children() , slideCount = $slides.length , $active = $('.active') , curActiveIndex = $('.active').index() , nextActiveIndex = curActiveIndex + 1; if(curActiveIndex == slideCount-1){ nextActiveIndex = 0; } $slides.eq(curActiveIndex).addClass('prev-out'); $slides.eq(nextActiveIndex).addClass('prev-in'); aniEndCallback($active,function($ele){ aniStatus = false; $active.removeClass('prev-out active'); $slides.eq(nextActiveIndex).removeClass('prev-in').addClass('active'); }); }); setInterval(function(){ $('.prev').trigger('click') },4000); });
精彩專題分享:jQuery圖片輪播 JavaScript圖片輪播 Bootstrap圖片輪播
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
- JavaScript+css+HTML實(shí)現(xiàn)移動端輪播圖(含源碼)
- 原生javascript+CSS實(shí)現(xiàn)輪播圖效果
- JS+CSS實(shí)現(xiàn)3D切割輪播圖
- 使用html+js+css 實(shí)現(xiàn)頁面輪播圖效果(實(shí)例講解)
- 原生js實(shí)現(xiàn)輪播圖的示例代碼
- js實(shí)現(xiàn)輪播圖的完整代碼
- js實(shí)現(xiàn)支持手機(jī)滑動切換的輪播圖片效果實(shí)例
- JS輪播圖實(shí)現(xiàn)簡單代碼
- js實(shí)現(xiàn)點(diǎn)擊左右按鈕輪播圖片效果實(shí)例
- js+css實(shí)現(xiàn)卡片輪播圖效果
相關(guān)文章
openlayers實(shí)現(xiàn)圖標(biāo)拖動獲取坐標(biāo)
這篇文章主要為大家詳細(xì)介紹了openlayers實(shí)現(xiàn)圖標(biāo)拖動獲取坐標(biāo),文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2020-09-09javascript 廣告移動特效的實(shí)現(xiàn)代碼
下面小編就為大家?guī)硪黄猨avascript 廣告移動特效的實(shí)現(xiàn)代碼。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-06-06JavaScript實(shí)現(xiàn)文件下載并重命名代碼實(shí)例
這篇文章主要介紹了JavaScript實(shí)現(xiàn)文件下載并重命名代碼實(shí)例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2019-12-12JS中將圖片base64轉(zhuǎn)file文件的兩種方式
這篇文章主要介紹了JS中圖片base64轉(zhuǎn)file文件的兩種方式,實(shí)現(xiàn)把圖片的base64編碼轉(zhuǎn)成file文件的功能,然后再上傳至服務(wù)器,本文結(jié)合實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2023-02-02JavaScript?onclick點(diǎn)擊事件-點(diǎn)擊切換圖片且自動播放
這篇文章主要介紹了JavaScript?onclick點(diǎn)擊事件-點(diǎn)擊切換圖片且自動播放,在頁面中放圖片并設(shè)置四個button,可以通過點(diǎn)擊上一張下一張來切換圖片,下面來看看具體的實(shí)現(xiàn)過程吧2022-01-01