日期:2014-05-17 浏览次数:20733 次
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>jQuery常用焦点图</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
body,ul,li{
font-size:12px; margin:0px; padding:0px;
}
ul,li{
list-style-type:none;
}
a{
color:#000; text-decoration:none;
}
.demo{
width:450px; height:200px; position:relative; margin:auto; border:#ddd 1px solid;padding:5px; overflow:hidden;
}
.demo ul{
position:relative; z-index:5;
}
.demo ul li{
position:absolute; display:none;
}
.num{
position:absolute;right:10px; bottom:10px; z-index:10;
}
.num a{
width:20px; height:20px; line-height:20px; display:inline-block; background-color:#333; text-align:center; margin:0 3px; cursor:pointer; text-decoration:none; color:#fff;
}
.num a.cur{
background:#ff6700;
}
</style>
<script type="text/javascript" src="jquery1.3.2.js"></script>
</head>
<body>
<div class="demo">
<ul>
<li style="display:block;"><a href="#/" target="_blank"><img src="1.jpg" /></a></li>
<li><a href="#" target="_blank"><img src="2.jpg" /></a></li>
<li><a href="#" target="_blank"><img src="3.jpg" /></a></li>
</ul>
<div class="num"><a class="cur">1</a><a>2</a><a>3</a></div>
</div>
<script type="text/javascript">
$(function(){
var sw = 0;
$(".demo .num a").mouseover(function(){
sw = $(".num a").index(this);
myShow(sw);
});
function myShow(i){
$(".demo .num a").eq(i).addClass("cur").siblings("a").removeClass("cur");
$(".demo ul li").eq(i).stop(true,true).fadeIn(600).siblings("li").fadeOut(600);
}
//滑入停止动画,滑出开始动画
$(".demo").hover(function(){
if(myTime){
clearInterval(myTime);
}
},function(){
myTime = setInterval(function(){
myShow(sw)
sw++;
if(sw==3){sw=0;}
} , 3000);
});
//自动开始
var myTime = setInterval(function(){
myShow(sw)
sw++;
if(sw==3){sw=0;}
} , 3000);
})
</script>
</body>
</html>