1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > Js+CSS淡入式效果图片幻灯切换效果

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

时间:2019-11-09 02:35:44

相关推荐

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

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8" />

<title>Js+CSS淡入式效果图片幻灯切换效果丨芯晴网页特效丨</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="//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="/images/m01.jpg" width="800" height="280" title="红叶传情"/></li>

<li><img src="/images/m02.jpg" width="800" height="280" title="野花绽放"/></li>

<li><img src="//images/m03.jpg" width="800" height="280" title="往事如茶"/></li>

<li><img src="//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="" target="_blank">芯晴网页特效</a>丨 收集于互联网,只为兴趣与学习交流,不作商业用途。来源:源码爱好者</font></p>

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。