国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

js實現單張圖片平移切換效果

2019-11-19 15:11:32
字體:
來源:轉載
供稿:網友

本文參考了JQuery實現圖片切換(自動切換+手動切換)

由于個人不需要手動切換功能,因此把那部分的內容刪了,主要是增加了無縫切換的效果。

原理也很簡單,大概是一張圖移動到左邊以后,從底部移回最右,等待下一次循環。

<!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實現圖片切換</h1>   <div id="focus">    <ul>     <!-- 這里有三個z-index的設置 -->     <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); //網頁打開立即執行一次動畫   picTimer = setInterval(function() {     index++;     if(index == len) {index = 0;}     showPics(index);    },3000);//3000毫秒的間隔  //顯示圖片函數,根據接收的index值顯示相應的內容   function showPics(index) { //普通切換    var nowLeft = -sWidth; //每次移動固定量   var $pic = $pics.eq(index);//獲取當前要移出的圖片   var $nexPic = $pics.eq((index+1)%len);//當前要移入的圖片   var $nexnexPic = $pics.eq((index+2)%len);//下一個要移入的圖片   $nexPic.css("left",sWidth);//下一個圖片移動到最右   //當前要移出的圖片開始左移,模式設為平滑"linear",速度和間隔一樣   $pic.animate({"left":nowLeft},3000,"linear",function(){    // 當前圖片完全移出后,重新設置z-index    $pic.css("z-index",1);    $nexPic.css("z-index",3);    $nexnexPic.css("z-index",2);   });   //當前要移入的圖片同時左移   $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> 

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 黄梅县| 沙田区| 九龙坡区| 北安市| 德惠市| 邢台县| 崇信县| 安宁市| 财经| 德江县| 黄骅市| 大城县| 屏东市| 雅安市| 满洲里市| 平凉市| 澎湖县| 嵊泗县| 启东市| 浦东新区| 剑阁县| 博野县| 宿迁市| 南城县| 泸州市| 霸州市| 宁南县| 凤翔县| 义马市| 尚义县| 怀宁县| 阆中市| 逊克县| 夹江县| 航空| 盖州市| 梧州市| 罗江县| 施甸县| 滦南县| 青河县|