JS實(shí)現(xiàn)滑動(dòng)導(dǎo)航效果
本文實(shí)例為大家分享了JS實(shí)現(xiàn)滑動(dòng)導(dǎo)航效果的具體代碼,供大家參考,具體內(nèi)容如下
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <style> * { padding: 0; margin: 0; } ul { list-style-type: none; height: 42px; position: absolute; } img { vertical-align: middle; } li, a { cursor: pointer; } a { text-decoration: none; color: #000000; display: block; } li { width: 83px; height: 42px; /*background-color: pink;*/ float: left; text-align: center; line-height: 42px; } .box { position: relative; width: 530px; height: 42px; border: 1px solid deepskyblue; margin: 100px auto; -webkit-border-radius: 10px; -moz-border-radius: 10px; border-radius: 10px; } .box img#cloud { width: 83px; height: 42px; position: absolute; left: 0; top: 0; } .box img#xinhao { position: absolute; right: 0; top: 50%; transform: translateY(-50%); } </style> </head> <body> <div class="box" id="box"> <img id="cloud" src="images/cloud.gif" alt="" /> <ul id="ull"> <li><a href="#">長(zhǎng)沙校區(qū)</a></li> <li><a href="#">長(zhǎng)沙校區(qū)</a></li> <li><a href="#">長(zhǎng)沙校區(qū)</a></li> <li><a href="#">長(zhǎng)沙校區(qū)</a></li> <li><a href="#">長(zhǎng)沙校區(qū)</a></li> <li><a href="#">長(zhǎng)沙校區(qū)</a></li> </ul> <img id="xinhao" src="images/rss.png" alt="" /> </div> <script src="js/common.js"></script> <script src="js/changespead.js"></script> <script> //獲取每一個(gè)li var list=my$('ull').children; console.log(list); //獲取到筋斗云圖片 var im=my$('cloud'); //獲取圖片的寬度 var imgWidth=im.offsetWidth; console.log(imgWidth); for(var i=0;i<list.length;i++){ //設(shè)置index值用來儲(chǔ)存移動(dòng)的距離 list[i].setAttribute('index',i); //遍歷所有l(wèi)i,每個(gè)li綁定三個(gè)時(shí)間指向同一個(gè)函數(shù)f1 list[i].onmouseover=f1; list[i].onmouseout=f1; list[i].onclick=f1; //實(shí)現(xiàn)函數(shù)f1 function f1(e){ switch(e.type) { case 'mouseover': //獲取當(dāng)前l(fā)i的index值 index=this.getAttribute('index'); //調(diào)用變速移動(dòng)函數(shù) movecs(im,imgWidth*index); break; case 'click': index=this.getAttribute('index'); //點(diǎn)擊之后固定 im.style.left=imgWidth*index+'px'; //點(diǎn)擊了其中一個(gè)li之后的操作,移開鼠標(biāo)之后不會(huì)彈回去 this.onmouseout=false; for(var k=0;k<list.length;k++){ list[k].setAttribute('jndex',k); list[k].onmouseover=function(){ jndex=this.getAttribute('jndex'); movecs(im,imgWidth*jndex); }; list[k].onmouseout=function(){ movecs(im,imgWidth*index); }; } break; case 'mouseout': index=0; movecs(im,imgWidth*index); break; } } } /*list[i].onmouseover=function(){ index=this.getAttribute('index'); console.log(index); movecs(im,imgWidth*index); }; list[i].onmouseout=function(){ index=0; // im.style.left='0px'; movecs(im,imgWidth*index); }; list[i].onclick=function(){ index=this.getAttribute('index'); im.style.left=imgWidth*index+'px'; alert(index); };*/ </script> </body> </html>
最終效果如下:云彩跟隨鼠標(biāo)移動(dòng),點(diǎn)擊固定
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- JS實(shí)現(xiàn)分頁(yè)導(dǎo)航效果
- JS實(shí)現(xiàn)音樂導(dǎo)航特效
- JS實(shí)現(xiàn)導(dǎo)航欄樓層特效
- JS中用三種方式實(shí)現(xiàn)導(dǎo)航菜單中的二級(jí)下拉菜單
- JS實(shí)現(xiàn)選中當(dāng)前菜單后高亮顯示的導(dǎo)航條效果
- 一個(gè)js控制的導(dǎo)航菜單實(shí)例代碼
- CSS3+Js實(shí)現(xiàn)響應(yīng)式導(dǎo)航條
- JS 實(shí)現(xiàn)導(dǎo)航欄懸停效果
- js實(shí)現(xiàn)無(wú)限級(jí)樹形導(dǎo)航列表效果代碼
- js+css實(shí)現(xiàn)扇形導(dǎo)航效果
相關(guān)文章
用JS動(dòng)態(tài)改變表單form里的action值屬性的兩種方法
下面小編就為大家?guī)硪黄肑S動(dòng)態(tài)改變表單form里的action值屬性的兩種方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-05-05總結(jié)JavaScript中布爾操作符||與&&的使用技巧
這篇文章主要介紹了總結(jié)JavaScript中布爾操作符||與&&的使用技巧,是JS入門學(xué)習(xí)中的基礎(chǔ)知識(shí),需要的朋友可以參考下2015-11-11javascript實(shí)現(xiàn)動(dòng)態(tài)CSS換膚技術(shù)的腳本
javascript實(shí)現(xiàn)動(dòng)態(tài)CSS換膚技術(shù)的腳本...2007-06-06bootstrap滾動(dòng)監(jiān)控器使用方法解析
這篇文章主要為大家詳細(xì)解析了bootstrap滾動(dòng)監(jiān)控器使用方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-01-01three.js 利用uv和ThreeBSP制作一個(gè)快遞柜功能
這篇文章主要介紹了three.js 利用uv和ThreeBSP制作一個(gè)快遞柜,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-08-08JavaScript輸出所選擇起始與結(jié)束日期的方法
這篇文章主要介紹了JavaScript輸出所選擇起始與結(jié)束日期的方法,涉及javascript結(jié)合HTML5元素操作日期運(yùn)算的相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2017-07-07JS運(yùn)動(dòng)框架之分享側(cè)邊欄動(dòng)畫實(shí)例
這篇文章主要介紹了JS運(yùn)動(dòng)框架之分享側(cè)邊欄動(dòng)畫,實(shí)例分析了javascript操作div及css的技巧,需要的朋友可以參考下2015-03-03前端js操作Cookie超詳細(xì)介紹與實(shí)戰(zhàn)案例
這篇文章主要給大家介紹了關(guān)于前端js操作Cookie詳細(xì)介紹與案例的相關(guān)資料,JS Cookie是一個(gè)用于在瀏覽器中操作Cookie的JavaScript庫(kù),它提供了一組簡(jiǎn)單的方法來設(shè)置、獲取、刪除和檢查 Cookie,需要的朋友可以參考下2023-09-09console.log()的作用與實(shí)現(xiàn)方式
這篇文章主要介紹了console.log()的作用與實(shí)現(xiàn)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-01-01