搜索 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Document</title>
<style type="text/css">
#titles,#lists,#wamp{overflow: hidden; }
#wamp{width: 600px; margin: 60px auto; border: 1px groove #ccc}
#titles{line-height: 50px;width: 100%;}
#titles span{float: left;height: 48px;width: 25%;text-align: center; border-bottom: 1px dotted #ccc; cursor: pointer;}
#titles span.active{font-weight: bold; background: #f2f2f2; border-bottom: 1px solid #ccc;
background: -moz-linear-gradient(center center, #999999 0%, #f2f2f2 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#999999), color-stop(100%,#f2f2f2));
background: -webkit-linear-gradient(top, #999999 0%,#f2f2f2 100%);
background: -o-linear-gradient(top, #999999 0%,#f2f2f2 100%);
background: -ms-linear-gradient(top, #999999 0%,#f2f2f2 100%);
background: linear-gradient(to bottom, #999999 0.6%,#f2f2f2 100%);
filter:alpha(opacity=100 finishopacity=50 style=1 startx=0,starty=0,finishx=0,finishy=150) progid:DXImageTransform.Microsoft.gradient(startcolorstr=red,endcolorstr=blue,gradientType=0);
-ms-filter:alpha(opacity=100 finishopacity=50 style=1 startx=0,starty=0,finishx=0,finishy=150) progid:DXImageTransform.Microsoft.gradient(startcolorstr=red,endcolorstr=blue,gradientType=0);
}
:root .gradient{filter:none;}
#lists{height: 200px;}
#listwin{width: 400%; height: 200px;margin-left: 0px;}
#listwin div{height: 200px;float: left;width: 25%;}
</style>
<script type="text/javascript" src="../Scripts/jquery.js"></script>//1.9版本的
<script type="text/javascript">
$(function () {
var curIndex=0,mlValue,index=1,timer="";
$('#titles span').on('click', function () {
curIndex = $(this).index();
mlValue = '-' + curIndex * 100 + '%';
$(this).addClass("active").siblings().removeClass("active");
$("#listwin").animate({ 'marginLeft': mlValue })
});
function next(){
timer=setInterval(function(){
$('#titles span:eq('+index+')').click();
index++;
if(index==$('#titles span').length){
index=0;
}
},5000);
}
next();
$("#wamp").on('mouseenter',function(){
clearInterval(timer);
})
$("#wamp").on('mouseleave',function(){
index=curIndex==3?0:curIndex+1;
next();
})
});
</script>
</head>
<body>
<div id="wamp">
<div id="titles">
<span class="active">切换标题</span>
<span>切换标题</span>
<span>切换标题</span>
<span>切换标题</span>
</div>
<div id="lists">
<div id="listwin">
<div>新闻内容1</div>
<div>新闻内容2</div>
<div>新闻内容3</div>
<div>新闻内容4</div>
</div>
</div>
</div>
</body>
</html>