jQuery實現(xiàn)的多屏圖像圖層切換效果實例
更新時間:2015年05月07日 16:16:24 投稿:shichen2014
這篇文章主要介紹了jQuery實現(xiàn)的多屏圖像圖層切換效果,可實現(xiàn)多個圖層的點擊切換效果,設(shè)計jQuery鼠標(biāo)事件及樣式的操作技巧,需要的朋友可以參考下
本文實例講述了jQuery實現(xiàn)多屏圖像圖層切換效果的方法。分享給大家供大家參考。具體實現(xiàn)方法如下:
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無標(biāo)題文檔</title>
<script type="text/javascript" src="jquery-1.6.2.min.js"></script>
<style type="text/css">
ul{list-style:none;margin:0;padding:0;}
li{float:left;}
.Xing_focus{
width:875px; height:800px;
overflow:hidden;border:1px solid red;
}
.Xing_focus ul{
width:3500px;
}
.bnt {
float:left;width:300px;height:20px;
border:1px solid red;
}
.bnt li{
width:18px;height:18px;
background:red; cursor:pointer;
margin-right:10px;float:left;
}
.bnt .sli{
background:blue;
}
.next{
width:100px;height:100px;
background:#990000;float:left;
cursor:pointer;
}
.pre{
width:100px;height:100px;
background:#009;float:left;
cursor:pointer;margin-right:30px;
}
.list1{
width:875px;height:500px;background:red;
}
.list2{
width:875px;height:500px;background:black;
}
.list3{
width:875px;height:500px;background:pink;
}
.list4{
width:875px;height:500px;background:blue;
}
</style>
</head>
<body>
<div class="Xing_focus" id="box">
<ul class="imgs" id="actor">
<li class="list1">
<img src="http://www.baidu.com/img/baidu_sylogo1.gif" />
</li>
<li class="list2">
<img src="http://www.baidu.com/img/baidu_sylogo1.gif" />
</li>
<li class="list3">
<img src="http://www.baidu.com/img/baidu_sylogo1.gif" />
</li>
<li class="list4">
<img src="http://www.baidu.com/img/baidu_sylogo1.gif" />
</li>
</ul>
<ul class="bnt" id="bnt">
</ul>
<div class="pre" id="pre">上一張</div>
<div class="next" id="next">下一張</div>
</div>
<script type="text/javascript">
$(window).load(function() {
var liW = $("#actor li:first").width();
var liL = $("#actor li").length;
//alert(liW)
var lis = $("#actor li").length;
for(i=0;i<lis;i++){
$("#bnt").append("<li></li>")
$("#bnt li:first").addClass("sli");
};
$("#bnt li").each(function(index) {
$(this).click(function(){
if($("#actor").is(":animated")==false){
$("#actor").animate({"marginLeft":-index*liW},500,function(){
$("#bnt li").removeClass("sli");
$("#bnt li").eq(index).addClass("sli");
});
};
});
});
settime=window.setInterval(atuoScroll,2000);
$("#box").hover(function(){
window.clearInterval(settime);
},function(){
settime=window.setInterval(atuoScroll,2000);
});
////////////////////////////////////////
$("#next").click(function(){
var ulM =parseInt( $("#actor").css("margin-left"));
if(ulM==-((liL-1)*liW)&&$("#actor").is(":animated")==false){
$("#actor").animate({"marginLeft":0+"px"},500,function(){
$("#bnt li").removeClass("sli");
$("#bnt li:first").addClass("sli");
});
}
else if($("#actor").is(":animated")==false){
$("#actor").animate({"marginLeft":ulM-liW+"px"},500,function(){
var ulM =parseInt( $("#actor").css("margin-left"));
var num = -ulM/liW
$("#bnt li").removeClass("sli");
$("#bnt li").eq(num).addClass("sli");
});
};
});
////////////////////////////////////////
$("#pre").click(function(){
var ulM =parseInt( $("#actor").css("margin-left"));
if(ulM==0&&$("#actor").is(":animated")==false){
$("#actor").animate({"marginLeft":-2625+"px"},500,function(){
$("#bnt li").removeClass("sli");
$("#bnt li:last").addClass("sli");
});
}
else if($("#actor").is(":animated")==false){
$("#actor").animate({"marginLeft":ulM+liW+"px"},500,function(){
var ulM =parseInt( $("#actor").css("margin-left"));
var num = -ulM/liW
$("#bnt li").removeClass("sli");
$("#bnt li").eq(num).addClass("sli");
});
};
});
//////////////////////////////////////
});//END
function atuoScroll(){
var liW = $("#actor li:first").width();
var liL = $("#actor li").length;
var ulM =parseInt( $("#actor").css("margin-left"));
if(ulM==-((liL-1)*liW)&&$("#actor").is(":animated")==false){
$("#actor").stop();
$("#actor").animate({"marginLeft":0},500,function(){
$("#bnt li").removeClass("sli");
$("#bnt li:first").addClass("sli");
});
}
else if($("#actor").is(":animated")==false){
$("#actor").stop();
$("#actor").animate({"marginLeft":ulM-liW},500,function(){
var ulM =parseInt( $("#actor").css("margin-left"));
var num = -ulM/liW
$("#bnt li").removeClass("sli");
$("#bnt li").eq(num).addClass("sli");
});
};
};
</script>
</body>
</html>
希望本文所述對大家的jQuery程序設(shè)計有所幫助。
相關(guān)文章
基于jquery實現(xiàn)的上傳圖片及圖片大小驗證、圖片預(yù)覽效果代碼
基于jquery實現(xiàn)的上傳圖片及圖片大小驗證、圖片預(yù)覽效果代碼,需要的朋友可以參考下。2011-04-04
jQuery focus和blur事件的應(yīng)用詳解
本篇文章主要是對jQuery中focus和blur事件的應(yīng)用進(jìn)行了介紹,需要的朋友可以過來參考下,希望對大家有所幫助2014-01-01
jQuery 開發(fā)之EasyUI 添加數(shù)據(jù)的實例
這篇文章主要介紹了jQuery 開發(fā)之EasyUI 添加數(shù)據(jù)的實例的相關(guān)資料,希望通過本文能幫助到大家,讓大家理解掌握這部分內(nèi)容,需要的朋友可以參考下2017-09-09
jQuery-serialize()輸出序列化form表單值的方法
jQuery-serialize()輸出序列化表單值在工作中很常見也很實用,于是本人搜集整理了一些,需要了解的朋友可以詳細(xì)參考下2012-12-12
jQuery增加、刪除及修改select option的方法
這篇文章主要介紹了jQuery增加、刪除及修改select option的方法,涉及jQuery針對form表單中select選項的常見操作技巧,需要的朋友可以參考下2016-08-08
jquery使用each方法遍歷json格式數(shù)據(jù)實例
這篇文章主要介紹了jquery使用each方法遍歷json格式數(shù)據(jù),實例分析了jQuery中each方法的使用技巧,需要的朋友可以參考下2015-05-05

