js實(shí)現(xiàn)固定寬高滑動(dòng)輪播圖效果
更新時(shí)間:2017年01月13日 16:31:39 作者:帶阿貍?cè)ヂ眯?
本文主要分享了js實(shí)現(xiàn)PC固定寬高滑動(dòng)輪播圖效果的示例代碼。具有一定的參考價(jià)值,下面跟著小編一起來看下吧
話不多說,請(qǐng)看具體示例代碼:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <script src="http://libs.baidu.com/jquery/1.9.1/jquery.js"></script> <style> *{ margin:0; padding:0; } html, body { position: relative; height: 100%; } body { background: #eee; font-size: 14px; color:#000; margin: 0; padding: 0; } li{ list-style: none; } a{ text-decoration: none; } #banner1{ width:500px; } .banner{ width: 500px; height:100px; border:1px solid red; position: relative; margin:40px auto 0; overflow: hidden; } .banner ul{ width:9999px; position: absolute; top:0; left: 0; height: 100%; } .banner li{ width:500px; float: left; height: 100%; line-height: 100px; } .banner li a{ display: block; background:green; font-size:30px; text-align: center; } .cur{ height: 20px; position: absolute; right: 0; bottom:10px; text-align: center; } .cur a{ display: inline-block; width: 20px; height: 20px; background:yellow; margin-left:2px; } .cur a.active{ background:red; } .prve{ position: absolute; top:50%; left: 0; width:30px; height: 30px; background: red; line-height: 30px; text-align:center; color:#fff; margin-top:-15px; } .next{ position: absolute; top:50%; right: 0; width:30px; height: 30px; background: red; line-height: 30px; text-align:center; color:#fff; margin-top:-15px; } </style> </head> <body> <div class="banner" id="banner1"> <ul class="tab"> <li><a href="###">1</a></li> <li><a href="###">2</a></li> <li><a href="###">3</a></li> </ul> <div class="cur"></div> <div class="prve"><</div> <div class="next">></div> </div> <script> $(function(){ cc("banner1",500); }); function cc(id,w){ var i=0; var id=$("#"+id); var tab=id.children(".tab"); var tabLi=tab.find("li"); var clone=tabLi.first().clone(); tab.append(clone); var size=tab.find("li").size(); var cur=id.children(".cur"); var curA=cur.children("a"); var prve=id.children(".prve"); var next=id.children(".next"); for(var j=0;j<size-1;j++){ cur.append("<a href='###'></a>"); } cur.find("a").first().addClass("active"); /*鼠標(biāo)劃入圓點(diǎn)*/ cur.find("a").hover(function(){ var index=$(this).index(); i=index; tab.stop().animate({left:-index*w},500) $(this).addClass("active").siblings().removeClass("active") }); /*自動(dòng)輪播*/ var t=setInterval(function(){ i++; move() },2000) /*對(duì)banner定時(shí)器的操作*/ id.hover(function(){ clearInterval(t); },function(){ t=setInterval(function(){ i++; move(); },2000) }); /*向左的按鈕*/ prve.click(function(){ i--; move(); }); /*向右的按鈕*/ next.click(function(){ i++; move(); }); function move(){ if(i==size){ tab.css({left:0}); i=1; }; if(i==-1){ tab.css({left:-(size-1)*w}); i=size-2; }; tab.stop().animate({left:-i*w},500); if(i==size-1){ cur.children("a").eq(0).addClass("active").siblings().removeClass("active") }else{ cur.children("a").eq(i).addClass("active").siblings().removeClass("active") }; }; } </script> </body> </html>
以上就是本文的全部?jī)?nèi)容,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來一定的幫助,同時(shí)也希望多多支持腳本之家!
您可能感興趣的文章:
- js實(shí)現(xiàn)滑動(dòng)輪播效果
- 原生JS無縫滑動(dòng)輪播圖
- js原生實(shí)現(xiàn)移動(dòng)端手指滑動(dòng)輪播圖效果的示例
- js實(shí)現(xiàn)從左向右滑動(dòng)式輪播圖效果
- JS實(shí)現(xiàn)自動(dòng)輪播圖效果(自適應(yīng)屏幕寬度+手機(jī)觸屏滑動(dòng))
- JS實(shí)現(xiàn)touch 點(diǎn)擊滑動(dòng)輪播實(shí)例代碼
- javascript經(jīng)典特效分享 手風(fēng)琴、輪播圖、圖片滑動(dòng)
- js實(shí)現(xiàn)支持手機(jī)滑動(dòng)切換的輪播圖片效果實(shí)例
- 原生js實(shí)現(xiàn)移動(dòng)開發(fā)輪播圖、相冊(cè)滑動(dòng)特效
- js實(shí)現(xiàn)上下滑動(dòng)輪播
相關(guān)文章
使用 Node.js 做 Function Test實(shí)現(xiàn)方法
這篇文章介紹了Node.js 做 Function Test實(shí)現(xiàn)方法,有需要的朋友可以參考一下2013-10-10JavaScript操作選擇對(duì)象的簡(jiǎn)單實(shí)例
下面小編就為大家?guī)硪黄狫avaScript操作選擇對(duì)象的簡(jiǎn)單實(shí)例。小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考,一起跟隨小編過來看看吧2016-05-05js通過Date對(duì)象實(shí)現(xiàn)倒計(jì)時(shí)動(dòng)畫效果
這篇文章主要為大家詳細(xì)介紹了js通過Date對(duì)象實(shí)現(xiàn)倒計(jì)時(shí)動(dòng)畫效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-10-10JS實(shí)現(xiàn)的漢字與Unicode碼相互轉(zhuǎn)化功能分析
這篇文章主要介紹了JS實(shí)現(xiàn)的漢字與Unicode碼相互轉(zhuǎn)化功能,結(jié)合實(shí)例形式分析了javascript實(shí)現(xiàn)漢字與Unicode碼轉(zhuǎn)換相關(guān)操作技巧與注意事項(xiàng),需要的朋友可以參考下2018-05-05JS實(shí)現(xiàn)仿蘋果底部任務(wù)欄菜單效果代碼
這篇文章主要介紹了JS實(shí)現(xiàn)仿蘋果底部任務(wù)欄菜單效果代碼,可實(shí)現(xiàn)鼠標(biāo)滑過顯示大圖標(biāo)功能,涉及javascript鼠標(biāo)事件及頁面元素遍歷并修改屬性的技巧,需要的朋友可以參考下2015-08-08JavaScript截取字符串的2個(gè)函數(shù)介紹
這篇文章主要介紹了JavaScript截取字符串的2個(gè)函數(shù)介紹,它們分別是substring和substr函數(shù),本文用實(shí)例講解了它們的用法,需要的朋友可以參考下2014-08-08