jquery实现图片切换代码
本文实例为大家分享了jquery实现图片切换的方法,供大家参考,具体内容如下
<html>
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/>
<title></title>
<scriptsrc="http://libs.baidu.com/jquery/2.0.0/jquery.js"></script>
<script>
$(function(){
varnum2=6;//用于设置当前选中olli的z-index值
$('olli').mouseover(function(e){
$(this).attr('class','current');
$(this).siblings().attr('class','');
num2++;
varnum=$(this).index();//存olli的序列号
$('ulli').eq(num).css('z-index',num2);
$('ulli').eq(num).css('left','600px');//修改ulli对应的序列号的样式,先把它的位置绝对定位到div外面
//$('ulli').eq(num).css('left','0');这句是静态css,下一句是动态css
$('ulli').eq(num).animate({left:'0'},50);//然后把它的位置又重新绝对定位到父元素上面这样就实现了一个动画的效果
});
});
</script>
<style>
*{
padding:0;margin:0;border:0;
}
.all{/*div的宽高设置成和五张图片的宽高一样*/
width:600px;
height:300px;
margin:100pxauto;/*div居中*/
position:relative;/*相对定位,便于子元素使用绝对定位*/
overflow:hidden;/*隐藏超出部分的图片*/
}
.allul{
position:relative;
z-index:1;
}
.allulli{
position:absolute;
left:0;
top:0;
}
.allol{
position:absolute;
z-index:2;/*显示在ul上面*/
right:10px;
bottom:10px;
}
.allolli{
width:20px;
height:20px;
background:#333;
border:1pxsolid#ccc;
font-weight:bold;
text-align:center;/*左右居中*/
line-height:20px;/*文本上下居中*/
float:left;
list-style:none;
margin-left:10px;
color:#ccc;
margin-top:10px;/*让放大的li和没有放大的li下边框对其*/
}
.allol.current{
width:30px;
height:30px;
line-height:30px;
border:1pxsolid#f60;
color:#f60;
margin-top:0;/*让放大的li和没有放大的li下边框对其*/
cursor:pointer;/*增强用户体验变小手*/
}
</style>
</head>
<body>
<divclass="all">
<ul>
<li><imgsrc="01.jpg"width="600"height="300"/></li>
<li><imgsrc="02.jpg"width="600"height="300"/></li>
<li><imgsrc="03.jpg"width="600"height="300"/></li>
<li><imgsrc="04.jpg"width="600"height="300"/></li>
<li><imgsrc="05.jpg"width="600"height="300"/></li>
</ul>
<ol>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<liclass="current">5</li>
</ol>
</div>
</body>
</html>
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。