JQuery/PHP

自制两边淡入淡出JQuery效果

阿里云

一些插件都不太好实现如下效果,综合考虑还是自己写一个效果,JS 代码的定义参数都标注清楚了,记录备用,以后可能会用得上。

HTML 代码

  1. <div class="motto" id="motto">
  2.     <ul class="mottoList">
  3.         <li>
  4.             <div class="pic left"><img src="images/motto/motto11.png"></div>
  5.             <div class="pic right"><img src="images/motto/motto12.png"></div>
  6.         </li>
  7.         <li>
  8.             <div class="pic left"><img src="images/motto/motto21.png"></div>
  9.             <div class="pic right"><img src="images/motto/motto22.png"></div>
  10.         </li>
  11.         <li>
  12.             <div class="pic left"><img src="images/motto/motto31.png"></div>
  13.             <div class="pic right"><img src="images/motto/motto32.png"></div>
  14.         </li>
  15.         <li>
  16.             <div class="pic left"><img src="images/motto/motto41.png"></div>
  17.             <div class="pic right"><img src="images/motto/motto42.png"></div>
  18.         </li>
  19.         <li>
  20.             <div class="pic left"><img src="images/motto/motto51.png"></div>
  21.             <div class="pic right"><img src="images/motto/motto52.png"></div>
  22.         </li>
  23.     </ul>
  24. </div>
也想出现在这里?联系我们
创客主机

CSS 代码

  1. .motto{position: absolute; right: 50%; top: 72px; margin-right: -580px;}
  2. .mottoList{width: 390px;}
  3. .mottoList li{position: absolute; left: 0; top: 0; width: 390px; height: 63px; display: none;}
  4. .mottoList li .pic{position: absolute; top: 0;}
  5. .mottoList li .left{left: -100px;}
  6. .mottoList li .right{right: -100px;}

JQ 代码

  1. var onIndex = 0;  //默认的高亮项
  2. var list = $("#motto ul");  //列表元素
  3. var li = list.children("li");  //选择列表下的每项
  4. var liLength = li.length;  //取得列表长度
  5. var easing = "swing";  //过渡曲线效果
  6. var distance = "100px";  //过渡效果的长度
  7. var interTime = 3000;  //间隔多久切换,单位毫秒
  8. var delayTime = 1000;  //切换动画时间,单位毫秒
  9. var idTime = interTime + delayTime;
  10. setFun(idTime);
  11. function setFun(setTime){
  12.     li.eq(onIndex).addClass("on").fadeIn(delayTime).children(".left").animate({left: 0 + "px"}, delayTime, easing).next(".right").stop(true, false).animate({right: 0 + "px"}, delayTime, easing);
  13.     setTimeout(function (){
  14.         li.eq(onIndex).removeClass("on").fadeOut(delayTime).children(".left").stop(true, false).animate({left: "-" + distance}, delayTime, easing).next(".right").animate({right: "-" + distance}, delayTime, easing);
  15.         if (onIndex >= liLength - 1){
  16.             onIndex = 0;
  17.         }else{
  18.             onIndex++;
  19.         }
  20.         setTimeout(function (){ setFun(idTime) }, delayTime);
  21.     }, setTime);
  22. }

自制两边淡入淡出 JQuery 效果

已有 169 人购买
查看演示升级 VIP立刻购买

收藏
(0)

发表回复

热销模板

Ashade - 作品展示摄影相册WordPress汉化主题
LensNews

本站承接 WordPress / PbootCMS / DedeCMS 等
系统建站、仿站、开发、定制等业务!