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

js實(shí)現(xiàn)單張圖片平移切換效果

 更新時(shí)間:2017年10月11日 16:01:31   作者:ueba  
這篇文章主要為大家詳細(xì)介紹了js實(shí)現(xiàn)單張圖片平移切換效果,一張圖移動(dòng)到左邊以后,從底部移回最右,等待下一次循環(huán),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文參考了JQuery實(shí)現(xiàn)圖片切換(自動(dòng)切換+手動(dòng)切換)

由于個(gè)人不需要手動(dòng)切換功能,因此把那部分的內(nèi)容刪了,主要是增加了無縫切換的效果。

原理也很簡(jiǎn)單,大概是一張圖移動(dòng)到左邊以后,從底部移回最右,等待下一次循環(huán)。

<!DOCTYPE html>
<html>
<head>
 <meta charset="utf-8">
 <script src="js/jquery-1.10.1.min.js"></script>
</head>
<body> 
 <div class="wrapper"> 
  <h1>jquer實(shí)現(xiàn)圖片切換</h1> 
  <div id="focus"> 
   <ul> 
    <!-- 這里有三個(gè)z-index的設(shè)置 -->
     <li><div class="switch_pic" style="z-index: 3;background: url('imgs/01.jpg') center center;background-size: cover;"></div></li> 
     <li><div class="switch_pic" style="z-index: 2;background: url('imgs/02.jpg') center center;background-size: cover;"></div></li> 
     <li><div class="switch_pic" style="z-index: 1;background: url('imgs/03.jpg') center center;background-size: cover;"></div></li> 
     <li><div class="switch_pic" style="background: url('imgs/04.jpg') center center;background-size: cover;"></div></li>
     <li><div class="switch_pic" style="background: url('imgs/meiko2.jpg') center center;background-size: cover;"></div></li>
     <li><div class="switch_pic" style="background: url('imgs/meiko7.jpg') center center;background-size: cover;"></div></li>
   </ul> 
   </div> 
  </div> 
  <script type="text/javascript">
  $(function() { 
  var sWidth = $("#focus").width(); 
  var len = $("#focus ul li").length; 
  var index = 0; 
  var picTimer; 
  var $pics = $("#focus ul li").find('.switch_pic');//獲取所有圖片

   showPics(index); //網(wǎng)頁打開立即執(zhí)行一次動(dòng)畫
   picTimer = setInterval(function() { 
    index++; 
    if(index == len) {index = 0;} 
    showPics(index); 
   },3000);//3000毫秒的間隔

  //顯示圖片函數(shù),根據(jù)接收的index值顯示相應(yīng)的內(nèi)容 
  function showPics(index) { //普通切換 
   var nowLeft = -sWidth; //每次移動(dòng)固定量

   var $pic = $pics.eq(index);//獲取當(dāng)前要移出的圖片
   var $nexPic = $pics.eq((index+1)%len);//當(dāng)前要移入的圖片
   var $nexnexPic = $pics.eq((index+2)%len);//下一個(gè)要移入的圖片
   $nexPic.css("left",sWidth);//下一個(gè)圖片移動(dòng)到最右

   //當(dāng)前要移出的圖片開始左移,模式設(shè)為平滑"linear",速度和間隔一樣
   $pic.animate({"left":nowLeft},3000,"linear",function(){
    // 當(dāng)前圖片完全移出后,重新設(shè)置z-index
    $pic.css("z-index",1);
    $nexPic.css("z-index",3);
    $nexnexPic.css("z-index",2);
   });
   //當(dāng)前要移入的圖片同時(shí)左移
   $nexPic.animate({"left":0},3000,"linear");
  } 
 }); 
</script>
<style type="text/css">
 *{margin:0;padding:0;} 
 body{font-size:12px;color:#222;font-family:Verdana,Arial,Helvetica,sans-serif;background:#f0f0f0;} 
 .clearfix:after{content: ".";display: block;height: 0;clear: both;visibility: hidden;} 
 .clearfix{zoom:1;} 
 ul,li{list-style:none;} 
 img{border:0;} 
 .wrapper{width:800px;margin:0 auto;padding-bottom:50px;} 
 h1{height:50px;line-height:50px;font-size:22px;font-weight:normal;font-family:"Microsoft YaHei",SimHei;margin-bottom:20px;} 

 #focus{width:450px;height:350px;overflow:hidden;position:relative;} 
 #focus ul{height:380px;position:absolute;} 
 #focus ul li{float:left;width:450px;height:350px;overflow:hidden;position:absolute;background:#000;} 
 #focus ul li div{position:absolute;overflow:hidden;width: 450px;height: 350px;} 
</style>
</body> 

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

相關(guān)文章

最新評(píng)論

九龙城区| 古浪县| 河间市| 承德县| 抚宁县| 孟连| 沁源县| 城固县| 乌鲁木齐县| 泾川县| 茶陵县| 延庆县| 重庆市| 湖南省| 通江县| 德阳市| 镇原县| 武夷山市| 化德县| 荣昌县| 东阿县| 和林格尔县| 新宁县| 正镶白旗| 泽库县| 洛宁县| 乌拉特后旗| 板桥市| 马关县| 汉阴县| 金乡县| 玛纳斯县| 遵化市| 安泽县| 章丘市| 永靖县| 乌拉特后旗| 塘沽区| 金坛市| 辰溪县| 贡嘎县|