jquery仿QQ商城帶左右按鈕控制焦點(diǎn)圖片切換滾動(dòng)效果
更新時(shí)間:2013年06月27日 18:12:07 作者:
jquery圖片特效制作仿騰訊QQ商城首頁(yè)banner焦點(diǎn)圖片輪播切換效果,帶索引按鈕控制和左右按鈕控制圖片切換,實(shí)例代碼如下,感興趣的朋友可以參考下哈
復(fù)制代碼 代碼如下:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jquery圖片滾動(dòng)仿QQ商城帶左右按鈕控制焦點(diǎn)圖片切換滾動(dòng)</title>
<meta name="description" content="jquery圖片特效制作仿騰訊QQ商城首頁(yè)banner焦點(diǎn)圖片輪播切換效果,帶索引按鈕控制和左右按鈕控制圖片切換" />
<style type="text/css">
*{margin:0;padding:0;}
body{font-size:12px;color:#222;font-family:Verdana,Arial,Helvetica,sans-serif;background:#f0f0f0;}
.clearfix:after{content: ".";display: block;height: 0;clear: both;visibility: hidden;}
.clearfix{zoom:1;}
ul,li{list-style:none;}
img{border:0;}
.wrapper{width:800px;margin:0 auto;padding-bottom:50px;}
h1{height:50px;line-height:50px;font-size:22px;font-weight:normal;font-family:"Microsoft YaHei",SimHei;margin-bottom:20px;}
/* focus */
#focus{width:800px;height:280px;overflow:hidden;position:relative;}
#focus ul{height:380px;position:absolute;}
#focus ul li{float:left;width:800px;height:280px;overflow:hidden;position:relative;background:#000;}
#focus ul li div{position:absolute;overflow:hidden;}
#focus .btnBg{position:absolute;width:800px;height:20px;left:0;bottom:0;background:#000;}
#focus .btn{position:absolute;width:780px;height:10px;padding:5px 10px;right:0;bottom:0;text-align:right;}
#focus .btn span{display:inline-block;_display:inline;_zoom:1;width:25px;height:10px;_font-size:0;margin-left:5px;cursor:pointer;background:#fff;}
#focus .btn span.on{background:#fff;}
#focus .preNext{width:45px;height:100px;position:absolute;top:90px;background:url(img/sprite.png) no-repeat 0 0;cursor:pointer;}
#focus .pre{left:0;}
#focus .next{right:0;background-position:right top;}
</style>
<script type="text/javascript" src="http://jt.875.cn/js/jquery.js"></script>
<script type="text/javascript">
$(function() {
var sWidth = $("#focus").width(); //獲取焦點(diǎn)圖的寬度(顯示面積)
var len = $("#focus ul li").length; //獲取焦點(diǎn)圖個(gè)數(shù)
var index = 0;
var picTimer;
//以下代碼添加數(shù)字按鈕和按鈕后的半透明條,還有上一頁(yè)、下一頁(yè)兩個(gè)按鈕
var btn = "<div class='btnBg'></div><div class='btn'>";
for(var i=0; i < len; i++) {
btn += "<span></span>";
}
btn += "</div><div class='preNext pre'></div><div class='preNext next'></div>";
$("#focus").append(btn);
$("#focus .btnBg").css("opacity",0.5);
//為小按鈕添加鼠標(biāo)滑入事件,以顯示相應(yīng)的內(nèi)容
$("#focus .btn span").css("opacity",0.4).mouseover(function() {
index = $("#focus .btn span").index(this);
showPics(index);
}).eq(0).trigger("mouseover");
//上一頁(yè)、下一頁(yè)按鈕透明度處理
$("#focus .preNext").css("opacity",0.2).hover(function() {
$(this).stop(true,false).animate({"opacity":"0.5"},300);
},function() {
$(this).stop(true,false).animate({"opacity":"0.2"},300);
});
//上一頁(yè)按鈕
$("#focus .pre").click(function() {
index -= 1;
if(index == -1) {index = len - 1;}
showPics(index);
});
//下一頁(yè)按鈕
$("#focus .next").click(function() {
index += 1;
if(index == len) {index = 0;}
showPics(index);
});
//本例為左右滾動(dòng),即所有l(wèi)i元素都是在同一排向左浮動(dòng),所以這里需要計(jì)算出外圍ul元素的寬度
$("#focus ul").css("width",sWidth * (len));
//鼠標(biāo)滑上焦點(diǎn)圖時(shí)停止自動(dòng)播放,滑出時(shí)開(kāi)始自動(dòng)播放
$("#focus").hover(function() {
clearInterval(picTimer);
},function() {
picTimer = setInterval(function() {
showPics(index);
index++;
if(index == len) {index = 0;}
},4000); //此4000代表自動(dòng)播放的間隔,單位:毫秒
}).trigger("mouseleave");
//顯示圖片函數(shù),根據(jù)接收的index值顯示相應(yīng)的內(nèi)容
function showPics(index) { //普通切換
var nowLeft = -index*sWidth; //根據(jù)index值計(jì)算ul元素的left值
$("#focus ul").stop(true,false).animate({"left":nowLeft},300); //通過(guò)animate()調(diào)整ul元素滾動(dòng)到計(jì)算出的position
$("#focus .btn span").stop(true,false).animate({"opacity":"0.4"},300).eq(index).stop(true,false).animate({"opacity":"1"},300); //為當(dāng)前的按鈕切換到選中的效果
}
});
</script>
</head>
<body>
<div class="wrapper">
<h1>jquery圖片滾動(dòng)仿QQ商城帶左右按鈕控制焦點(diǎn)圖片切換滾動(dòng)</h1>
<div id="focus">
<ul>
<li><a target="_blank"><img src="img/01.jpg" alt="QQ商城焦點(diǎn)圖效果下載" /></a></li>
<li><a target="_blank"><img src="img/02.jpg" alt="QQ商城焦點(diǎn)圖效果教程" /></a></li>
<li><a target="_blank"><img src="img/03.jpg" alt="jquery商城焦點(diǎn)圖效果" /></a></li>
<li><a target="_blank"><img src="img/04.jpg" alt="jquery商城焦點(diǎn)圖代碼" /></a></li>
<li><a target="_blank"><img src="img/05.jpg" alt="jquery商城焦點(diǎn)圖源碼" /></a></li>
</ul>
</div><!--focus end-->
</div><!-- wrapper end -->
</body>
</html>
效果圖如下:

您可能感興趣的文章:
- jquery實(shí)現(xiàn)點(diǎn)擊左右按鈕切換圖片
- 使用jQuery實(shí)現(xiàn)鼠標(biāo)點(diǎn)擊左右按鈕滑動(dòng)切換
- 基于jquery實(shí)現(xiàn)左右按鈕點(diǎn)擊的圖片切換效果
- jquery帶有索引按鈕且自動(dòng)輪播切換特效代碼分享
- jQuery幻燈片特效代碼分享 鼠標(biāo)滑過(guò)按鈕時(shí)切換(2)
- Jquery幻燈片特效代碼分享?鼠標(biāo)點(diǎn)擊按鈕時(shí)切換(1)
- 基于jquery插件制作左右按鈕與標(biāo)題文字圖片切換效果
- jquery實(shí)現(xiàn)隱藏與顯示動(dòng)畫(huà)效果/輸入框字符動(dòng)態(tài)遞減/導(dǎo)航按鈕切換
- jQuery實(shí)現(xiàn)簡(jiǎn)單的按鈕顏色變化
相關(guān)文章
jQuery實(shí)現(xiàn)的右下角廣告窗體跟隨效果示例
這篇文章主要介紹了jQuery實(shí)現(xiàn)的右下角廣告窗體跟隨效果,涉及jQuery結(jié)合時(shí)間函數(shù)動(dòng)態(tài)操作頁(yè)面元素屬性的相關(guān)技巧,需要的朋友可以參考下2016-09-09jquery構(gòu)造器的實(shí)現(xiàn)代碼小結(jié)
jQuery的$符號(hào)非常神奇,它可以接受一個(gè)字符,也可以接受一個(gè)文檔對(duì)象或window對(duì)象,亦可以傳個(gè)函數(shù)進(jìn)行變?yōu)閐omReady加載器2011-05-05父頁(yè)面顯示遮罩層彈出半透明狀態(tài)的dialog
本文為大家介紹下父頁(yè)面顯示遮罩層,彈出半透明狀態(tài)的dialog。dialog即彈出的子頁(yè)面,需要的朋友可以參考下2014-03-03jQuery EasyUI之驗(yàn)證框validatebox實(shí)例詳解
本文通過(guò)實(shí)例代碼給大家講解了jQuery EasyUI之驗(yàn)證框validatebox知識(shí),非常不錯(cuò),具有參考借鑒價(jià)值,需要的的朋友參考下吧2017-04-04jquery實(shí)現(xiàn)固定頂部導(dǎo)航效果(仿蘑菇街)
蘑菇街導(dǎo)航固定頂部的效果想必大伙有所關(guān)注吧,想實(shí)現(xiàn)吧,本文將帶你走完實(shí)現(xiàn)之旅,接下來(lái)的代碼是使用jquery,感興趣的各位可不要錯(cuò)過(guò)了哈2013-03-03jQuery中調(diào)用WebService方法小結(jié)
以前在寫(xiě)ajax請(qǐng)求時(shí),總是喜歡使用jQuery+ashx的方式進(jìn)行調(diào)用,今天采取jQuery+WebService的方法來(lái)做ajax請(qǐng)求,發(fā)現(xiàn)這種方式比使用ashx的方式要更方便。2011-03-03JQuery 學(xué)習(xí)筆記 element屬性控制
JQuery元素屬性控制2009-07-07jQuery實(shí)現(xiàn)響應(yīng)鼠標(biāo)滾動(dòng)的動(dòng)感菜單效果
這篇文章主要介紹了jQuery實(shí)現(xiàn)響應(yīng)鼠標(biāo)滾動(dòng)的動(dòng)感菜單效果,可實(shí)現(xiàn)鼠標(biāo)滑過(guò)菜單項(xiàng)呈現(xiàn)文字上下滑動(dòng)變換的效果,涉及jQuery頁(yè)面元素樣式的動(dòng)態(tài)設(shè)置技巧,需要的朋友可以參考下2015-09-09