商城常用滾動(dòng)的焦點(diǎn)圖效果代碼簡(jiǎn)單實(shí)用
更新時(shí)間:2013年03月28日 14:26:51 作者:
此效果在網(wǎng)上使用的頻率比較多一點(diǎn)但大多是插件,要么JS寫(xiě)的太過(guò)于復(fù)雜童鞋們看起來(lái)有一定的難度,這個(gè)相對(duì)來(lái)說(shuō)比較簡(jiǎn)單一點(diǎn),感興趣的可以參考下哈
這種商城的效果網(wǎng)上很多,但大多是插件,要么JS寫(xiě)的太過(guò)于復(fù)雜,對(duì)于學(xué)習(xí)的童鞋來(lái)說(shuō)看起來(lái)比較費(fèi)勁,這個(gè)看起來(lái)比較簡(jiǎn)單,也比較容易理解,各位童鞋需要的請(qǐng)圍觀,也歡迎各位評(píng)價(jià),貼代碼(為方便使用,代碼復(fù)制即可用,無(wú)需另外添加?xùn)|西):
<!doctype html>
<html lang="en">
<head>
<title>商城常用滾動(dòng)的效果,簡(jiǎn)單實(shí)用</title>
<script type="text/javascript" src="http://jt.875.cn/js/jquery.js"></script>
<script type="text/javascript">
$(function(){
var len = $(".num > li").length;
var index = 0;
var adTimer;
$(".num li").mouseover(function(){
index = $(".num li").index(this);
showImg(index);
}).eq(0).mouseover();
//滑入 停止動(dòng)畫(huà),滑出開(kāi)始動(dòng)畫(huà).
$('.ad').hover(function(){
clearInterval(adTimer);
},function(){
adTimer = setInterval(function(){
showImg(index)
index++;
if(index==len){index=0;}
} , 3000);
}).trigger("mouseleave");
})
// 通過(guò)控制top ,來(lái)顯示不同的幻燈片
function showImg(index){
var adHeight = $(".content .ad").height();
$(".slider").stop(true,false).animate({top : -adHeight*index},1000);
$(".num li").removeClass("on")
.eq(index).addClass("on");
}
</script>
<style type="text/css">
ul,li{ margin:0;padding:0;}
.ad { margin-bottom:10px;width:586px; height:150px; overflow:hidden;position:relative;}
.content .slider,.content .num{position:absolute;}
.content .slider li{list-style:none;display:inline;}
.content .slider img{ width:586px; height:150px;display:block;}
.content .num{ right:5px; bottom:5px;}
.content .num li{float: left;color: #FF7300;text-align: center; line-height: 16px;width: 16px;height: 16px;font-family: Arial; font-size: 12px;cursor: pointer;overflow: hidden;margin: 3px 1px;border: 1px solid #FF7300;background-color: #fff;
}
.content .num li.on{color: #fff;line-height: 21px;width: 21px;height: 21px; font-size: 16px;margin: 0 1px;border: 0;background-color: #FF7300;font-weight: bold;}
</style>
</head>
<body>
<div class="content">
<div class="ad" >
<ul class="slider" >
<li><img src="http://pic.875.cn/upload/2013-03-26/1504517406.jpg" width="586" height="150"/></li>
<li><img src="http://pic.875.cn/upload/2013-01-24/1634016671.jpg" width="586" height="150"/></li>
<li><img src="http://pic.875.cn/upload/2013-03-07/1506174974.jpg" width="586" height="150"/></li>
<li><img src="http://pic.875.cn/upload/2013-03-26/1504517406.jpg" width="586" height="150"/></li>
<li><img src="http://pic.875.cn/upload/2013-01-24/1634016671.jpg" width="586" height="150"/></li>
</ul>
<ul class="num" >
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ul>
</div>
</div>
</body>
</html>
效果圖如下:
復(fù)制代碼 代碼如下:
<!doctype html>
<html lang="en">
<head>
<title>商城常用滾動(dòng)的效果,簡(jiǎn)單實(shí)用</title>
<script type="text/javascript" src="http://jt.875.cn/js/jquery.js"></script>
<script type="text/javascript">
$(function(){
var len = $(".num > li").length;
var index = 0;
var adTimer;
$(".num li").mouseover(function(){
index = $(".num li").index(this);
showImg(index);
}).eq(0).mouseover();
//滑入 停止動(dòng)畫(huà),滑出開(kāi)始動(dòng)畫(huà).
$('.ad').hover(function(){
clearInterval(adTimer);
},function(){
adTimer = setInterval(function(){
showImg(index)
index++;
if(index==len){index=0;}
} , 3000);
}).trigger("mouseleave");
})
// 通過(guò)控制top ,來(lái)顯示不同的幻燈片
function showImg(index){
var adHeight = $(".content .ad").height();
$(".slider").stop(true,false).animate({top : -adHeight*index},1000);
$(".num li").removeClass("on")
.eq(index).addClass("on");
}
</script>
<style type="text/css">
ul,li{ margin:0;padding:0;}
.ad { margin-bottom:10px;width:586px; height:150px; overflow:hidden;position:relative;}
.content .slider,.content .num{position:absolute;}
.content .slider li{list-style:none;display:inline;}
.content .slider img{ width:586px; height:150px;display:block;}
.content .num{ right:5px; bottom:5px;}
.content .num li{float: left;color: #FF7300;text-align: center; line-height: 16px;width: 16px;height: 16px;font-family: Arial; font-size: 12px;cursor: pointer;overflow: hidden;margin: 3px 1px;border: 1px solid #FF7300;background-color: #fff;
}
.content .num li.on{color: #fff;line-height: 21px;width: 21px;height: 21px; font-size: 16px;margin: 0 1px;border: 0;background-color: #FF7300;font-weight: bold;}
</style>
</head>
<body>
<div class="content">
<div class="ad" >
<ul class="slider" >
<li><img src="http://pic.875.cn/upload/2013-03-26/1504517406.jpg" width="586" height="150"/></li>
<li><img src="http://pic.875.cn/upload/2013-01-24/1634016671.jpg" width="586" height="150"/></li>
<li><img src="http://pic.875.cn/upload/2013-03-07/1506174974.jpg" width="586" height="150"/></li>
<li><img src="http://pic.875.cn/upload/2013-03-26/1504517406.jpg" width="586" height="150"/></li>
<li><img src="http://pic.875.cn/upload/2013-01-24/1634016671.jpg" width="586" height="150"/></li>
</ul>
<ul class="num" >
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ul>
</div>
</div>
</body>
</html>
效果圖如下:

您可能感興趣的文章:
- jquery 實(shí)現(xiàn)京東商城、凡客商城的圖片放大效果
- 發(fā)一個(gè)php簡(jiǎn)單的偽原創(chuàng)程序,配合商城采集用的
- 萬(wàn)網(wǎng)獨(dú)享主機(jī)Apache為Ecshop商城添加404頁(yè)面的方法詳解
- jQuery實(shí)戰(zhàn)之仿淘寶商城左側(cè)導(dǎo)航效果
- 基于JQuery實(shí)現(xiàn)的類(lèi)似購(gòu)物商城的購(gòu)物車(chē)
- php網(wǎng)上商城購(gòu)物車(chē)設(shè)計(jì)代碼分享
- jquery仿京東導(dǎo)航/仿淘寶商城左側(cè)分類(lèi)導(dǎo)航下拉菜單效果
- jquery仿QQ商城帶左右按鈕控制焦點(diǎn)圖片切換滾動(dòng)效果
- python抓取京東商城手機(jī)列表url實(shí)例代碼
- 使用Nopcommerce為商城添加滿XX減XX優(yōu)惠券功能
相關(guān)文章
JQuery事件e參數(shù)的方法preventDefault()取消默認(rèn)行為
JQuery事件的e參數(shù)的方法preventDefault()可以取消對(duì)象的默認(rèn)行為,下有個(gè)不錯(cuò)的示例,大家可以參考下,希望對(duì)大家有所幫助2013-09-09jQuery中:last-child選擇器用法實(shí)例
這篇文章主要介紹了jQuery中:last-child選擇器用法,實(shí)例分析了:last-child選擇器功能、定義及匹配父元素的最后一個(gè)子元素用法技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2014-12-12jQuery使用empty()方法刪除元素及其所有子元素的方法
這篇文章主要介紹了jQuery使用empty()方法刪除元素及其所有子元素的方法,涉及jQuery操作元素的技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-03-03jquery文檔操作wrap()方法實(shí)例簡(jiǎn)述
這篇文章主要介紹了jquery文檔操作wrap()方法,以實(shí)例形式簡(jiǎn)單分析了wrap()方法用某個(gè)標(biāo)簽將某個(gè)元素包起來(lái)的使用技巧,需要的朋友可以參考下2015-01-01關(guān)于jQuery object and DOM element
本篇文章,小編將為大家介紹,關(guān)于jQuery object and DOM element,有需要的朋友可以參考一下2013-04-04關(guān)于JavaScript和jQuery的類(lèi)型判斷詳解
下面小編就為大家?guī)?lái)一篇淺談JavaScript和jQuery的類(lèi)型判斷。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-10-10