商城常用滾動的焦點圖效果代碼簡單實用
更新時間:2013年03月28日 14:26:51 作者:
此效果在網(wǎng)上使用的頻率比較多一點但大多是插件,要么JS寫的太過于復(fù)雜童鞋們看起來有一定的難度,這個相對來說比較簡單一點,感興趣的可以參考下哈
這種商城的效果網(wǎng)上很多,但大多是插件,要么JS寫的太過于復(fù)雜,對于學(xué)習(xí)的童鞋來說看起來比較費勁,這個看起來比較簡單,也比較容易理解,各位童鞋需要的請圍觀,也歡迎各位評價,貼代碼(為方便使用,代碼復(fù)制即可用,無需另外添加?xùn)|西):
<!doctype html>
<html lang="en">
<head>
<title>商城常用滾動的效果,簡單實用</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();
//滑入 停止動畫,滑出開始動畫.
$('.ad').hover(function(){
clearInterval(adTimer);
},function(){
adTimer = setInterval(function(){
showImg(index)
index++;
if(index==len){index=0;}
} , 3000);
}).trigger("mouseleave");
})
// 通過控制top ,來顯示不同的幻燈片
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>商城常用滾動的效果,簡單實用</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();
//滑入 停止動畫,滑出開始動畫.
$('.ad').hover(function(){
clearInterval(adTimer);
},function(){
adTimer = setInterval(function(){
showImg(index)
index++;
if(index==len){index=0;}
} , 3000);
}).trigger("mouseleave");
})
// 通過控制top ,來顯示不同的幻燈片
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 實現(xiàn)京東商城、凡客商城的圖片放大效果
- 發(fā)一個php簡單的偽原創(chuàng)程序,配合商城采集用的
- 萬網(wǎng)獨享主機(jī)Apache為Ecshop商城添加404頁面的方法詳解
- jQuery實戰(zhàn)之仿淘寶商城左側(cè)導(dǎo)航效果
- 基于JQuery實現(xiàn)的類似購物商城的購物車
- php網(wǎng)上商城購物車設(shè)計代碼分享
- jquery仿京東導(dǎo)航/仿淘寶商城左側(cè)分類導(dǎo)航下拉菜單效果
- jquery仿QQ商城帶左右按鈕控制焦點圖片切換滾動效果
- python抓取京東商城手機(jī)列表url實例代碼
- 使用Nopcommerce為商城添加滿XX減XX優(yōu)惠券功能
相關(guān)文章
JQUERY實現(xiàn)網(wǎng)頁右下角固定位置展開關(guān)閉特效的方法
這篇文章主要介紹了JQUERY實現(xiàn)網(wǎng)頁右下角固定位置展開關(guān)閉特效的方法,涉及jquery操作頁面元素的顯示與隱藏等相關(guān)技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-07-07
jQuery列表動態(tài)增加和刪除的實現(xiàn)方法
這篇文章主要給大家介紹了關(guān)于jQuery列表動態(tài)增加和刪除的實現(xiàn)方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-11-11
easyui Draggable組件實現(xiàn)拖動效果
Draggable是easyui中用于實現(xiàn)拖拽功能的一個插件。利用它,我們可以實現(xiàn)控件的拖拽效果。Draggble覆蓋默認(rèn)值$.fn.draggable.defaults。2015-08-08

