JS實(shí)現(xiàn)滑動(dòng)導(dǎo)航效果

本文實(shí)例為大家分享了JS實(shí)現(xiàn)滑動(dòng)導(dǎo)航效果的具體代碼,供大家參考,具體內(nèi)容如下

成都創(chuàng)新互聯(lián)服務(wù)項(xiàng)目包括庫(kù)爾勒網(wǎng)站建設(shè)、庫(kù)爾勒網(wǎng)站制作、庫(kù)爾勒網(wǎng)頁(yè)制作以及庫(kù)爾勒網(wǎng)絡(luò)營(yíng)銷(xiāo)策劃等。多年來(lái),我們專(zhuān)注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢(shì)、行業(yè)經(jīng)驗(yàn)、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機(jī)構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,庫(kù)爾勒網(wǎng)站推廣取得了明顯的社會(huì)效益與經(jīng)濟(jì)效益。目前,我們服務(wù)的客戶(hù)以成都為中心已經(jīng)輻射到庫(kù)爾勒省份的部分城市,未來(lái)相信會(huì)繼續(xù)擴(kuò)大服務(wù)區(qū)域并繼續(xù)獲得客戶(hù)的支持與信任!

<!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值用來(lái)儲(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之后的操作,移開(kāi)鼠標(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)擊固定

JS實(shí)現(xiàn)滑動(dòng)導(dǎo)航效果

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。

網(wǎng)站名稱(chēng):JS實(shí)現(xiàn)滑動(dòng)導(dǎo)航效果
URL地址:http://bm7419.com/article4/gijjoe.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供搜索引擎優(yōu)化、App設(shè)計(jì)域名注冊(cè)、網(wǎng)站導(dǎo)航自適應(yīng)網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

h5響應(yīng)式網(wǎng)站建設(shè)