Js+CSS淡入式效果图片幻灯切换效果

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Js+CSS淡入式效果图片幻灯切换效果丨芯晴网页特效丨CsrCode.Cn</title>
<style type="text/css">
* {margin:0; padding:0;}
#focus {width:800px; height:280px; overflow:hidden; position:relative;}
#focus ul {height:280px; position:absolute;}
#focus ul li {float:left; width:800px; height:280px; overflow:hidden; position:relative; background:#000;}
#focus .btnBg {position:absolute; width:800px; height:20px; left:0; bottom:0; background:#000; text-align:right; color:#FFF;}
#focus .btn {position:absolute; width:780px; height:10px; padding:5px 10px;bottom:0; text-align:right; z-index:4}
#focus .btn span {display:block;width:25px; float:left; height:10px; font-size:10px; text-align:center; margin-left:5px; cursor:pointer; background:#fff;}
.title{ float:right; margin-right:20px;}
.red{ color:red;}
.sm{ text-align:right;position:absolute; bottom:0; right:0; width:800px; height:20px; line-height:20px; z-index:3;}
</style>
<script src="http://www.csrcode.cn//images/jquery-1.6.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
 var sWidth=$("#focus").width();
 var sHeight = $("#focus").height();
 var len=$("#focus ul li").length;
 var sWidth=$("#focus").width();
 var sm=$("<div class='sm'></div>")
 var index=0;
 var picTimer;
 var btn="<div class='btnBg'></div><div class='btn'>";
 for(var i=0;i<len; i++){
  var ii=i+1;
  btn +="<span>"+ii+"</span>";
  }
  $("#focus").append(btn);
  $("#focus").append(sm);
  $("#focus .btnBg").css("opacity",0.3);
  $("#focus .btn span").css("opacity",0.4).mouseenter(function(){
  index = $("#focus .btn span").index(this);
  sh(index);//向上滚动则改为showTop,向左滚动则改为showLeft,渐隐渐现则为sh
  }).eq(0).trigger("mouseenter");
  $("#focus").hover(function(){   
    clearInterval(picTimer);
    },function(){
    picTimer=setInterval(function(){
      sh(index);//向上滚动则改为showTop,向左滚动则改为showLeft,渐隐渐现则为sh
      index++;
      if(index==len){index=0;}
      },5000) //滚动间隔,数越大间隔越长
     }).trigger("mouseleave");
  
  
  function sh(index){
   $("#focus ul").css({"width":sWidth,"height":sHeight});
   var title=$("#focus img").eq(index).attr("title")
   $(".sm").empty();
   $(".sm").append(title)
   $("#focus ul li img").css({position:"absolute",top:0,left:0}).parent().eq(index).stop(true,true).animate({"opacity":1},2000).css({display:"block"}).siblings().stop(true,true).animate({"opacity":0.2},1000).css({display:"none"});
   $("#focus .btn span").stop(true,false).animate({"opacity":0.4},300).removeClass("red").eq(index).stop(true,false).animate({"opacity":0.8},300).addClass("red");
   }
  function showLeft(index){
   $("#focus ul").css("width",sWidth*len);
   var nowLeft=-index*sWidth;
   var title=$("#focus img").eq(index).attr("title")
   $("#focus .sm").empty();
   $("#focus .sm").append(title)
   $("#focus ul").stop(true,false).animate({"left":nowLeft},300);
   $("#focus .btn span").stop(true,false).animate({"opacity":0.4},300).removeClass("red").eq(index).stop(true,false).animate({"opacity":0.8},300).addClass("red");
   }
  function showTop(index) {
   $("#focus ul").css("height",sHeight*len);
   var nowTop = -index*sHeight;
   var title=$("img").eq(index).attr("title")
   $(".sm").empty();
   $(".sm").append(title)
   $("#focus ul").stop(true,false).animate({"top":nowTop},300);
   $("#focus .btn span").stop(true,false).animate({"opacity":"0.4"},300).removeClass("red").eq(index).stop(true,false).animate({"opacity":"1"},300).addClass("red");
 }
})
</script>
</head>
<body>
<div id="focus">
  <ul>
   <li><img src="http://www.csrcode.cn/images/m01.jpg" width="800" height="280" title="红叶传情"/></li>
   <li><img src="http://www.csrcode.cn/images/m02.jpg" width="800" height="280" title="野花绽放"/></li>
   <li><img src="http://www.csrcode.cn//images/m03.jpg" width="800" height="280" title="往事如茶"/></li>
   <li><img src="http://www.csrcode.cn//images/m04.jpg" width="800" height="280" title="油菜花开"/></li>
  </ul>
 </div>
</body>
</html>

<br>第一次运行本代码,请刷新一下本页面先~~<br>所需js文件:<a href="/images/jquery-1.6.2.min.js">jquery-1.6.2.min.js</a><hr><p align="center"><font color=black>本特效由 <a href="http://www.CsrCode.cn" target="_blank">芯晴网页特效</a>丨CsrCode.Cn 收集于互联网,只为兴趣与学习交流,不作商业用途。来源:源码爱好者</font></p>

转载于:https://www.cnblogs.com/csr04/archive/2012/08/23/2652821.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值