jQuery打造淘寶展示效果和淘寶輪播圖
淘寶展示效果
效果地址:http://www.sunyimin.cn/web22.0/14jq.html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>淘寶展示圖</title>
<script src="js/jquery-1.12.3.min.js" ></script>
<script>
$(document).ready(function(){
var $img = $('img');
var arrPos = [];
var blankIndex = 8;
var prevIndex = -1;
var arr = [
[1,3],
[0,2,4],
[1,5],
[0,4,6],
[1,3,5,7],
[2,4,8],
[3,7],
[4,6,8],
[5,7]
];
// 通過佈局轉化 將浮動佈局轉為絕對定位佈局
$img.each(function(i,elem){
arrPos.push( [ $(elem).position().left , $(elem).position().top ] );//儲存各個img的left值和top值
});
$img.each(function(i,elem){
$(elem).css('position','absolute');
$(elem).css('left',arrPos[i][0]);
$(elem).css('top',arrPos[i][1]); //給每個img加上絕對定位,並賦上left值和top值
});
$img.each(function(i,elem){
$(elem).attr('_index',i); //給各個img添上索引值
});
function move(){
var nowArr = arr[blankIndex];
var filterArr = [];
for(var i=0;i<nowArr.length;i++){
if( nowArr[i] != prevIndex ){
filterArr.push(nowArr[i]);
}
}
var nowIndex = filterArr[ Math.floor(Math.random()*filterArr.length) ];
prevIndex = blankIndex;
var iLeft = blankIndex%3 * 200;
var iTop = Math.floor(blankIndex/3) * 200;
var tmp = '';
$img.each(function(i,elem){
if( $(elem).attr('_index') == nowIndex ){
$(elem).animate({ left : iLeft, top : iTop },1000,function(){
tmp = blankIndex;
blankIndex = nowIndex;
$(elem).attr('_index' , tmp);
move();
});
}
});
}
move();
})
</script>
<style type="text/css">
body,h1,h2,h3,h4,h5,h6,p,dl,dd,ul,ol,pre,form,input,textarea,th,td,select{margin:0; padding:0;}
em{ font-style:normal;}
li{list-style:none;}
a{text-decoration:none;}
img{border:none;vertical-align:top;}
table{border-collapse;}
textarea{ resize:none; overflow:auto;}
#box{width:600px;height:600px;border: 1px solid #000;position: relative;margin:200px auto;}
#box img{width:200px;height:200px;float: left;}
</style>
</head>
<body>
<div id="box">
<img src="img/1.jpg">
<img src="img/2.jpg">
<img src="img/3.jpg">
<img src="img/4.jpg">
<img src="img/5.jpg">
<img src="img/6.jpg">
<img src="img/7.jpg">
<img src="img/8.jpg">
</div>
</body>
</html>
淘寶輪播圖
效果地址:http://www.sunyimin.cn/web23.0/15jq.html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>淘寶輪播圖</title>
<style type="text/css">
body,h1,h2,h3,h4,h5,h6,p,dl,dd,ul,ol,pre,form,input,textarea,th,td,select{margin:0; padding:0;}
em{ font-style:normal;}
li{list-style:none;}
a{text-decoration:none;}
img{border:none;vertical-align:top;}
table{border-collapse;}
textarea{ resize:none; overflow:auto;}
#wrap{width:470px;height:150px;border:1px solid #000;margin: 200px auto;position: relative;overflow: hidden;}
#wrap .list1{width:470px;height:150px;position: relative;}
#wrap .list1 li{width:470px;height:150px;position: absolute;}
#wrap .list2 {position: absolute;right:4px;bottom:4px;}
#wrap .list2 li{width:20px;height:20px;background: #fff;color:#ff6600;float: left;line-height: 20px;text-align: center;margin: 4px;cursor: pointer;}
#wrap .list2 .active{color:#fff;background:#ff6600;}
</style>
<script src="js/jquery-1.12.3.min.js" ></script>
<script>
$(document).ready(function(){
$('.list1 li').slice(1,5).css('left','470px');
var prevIndex=0;
var timer=null;
$('.list2 li').on('mouseover',function(){
clearTimeout(timer);
timer=setTimeout($.proxy(function(){ //工具函式$.proxy() 改變函式的this指向
$(this).attr('class','active').siblings().attr('class','');
if( prevIndex<$(this).index()){ //往左走
$('.list1 li').eq($(this).index()).css('left','470px');
$('.list1 li').eq(prevIndex).animate({left:-470},500);
}else if(prevIndex>$(this).index()){ //往右走
$('.list1 li').eq($(this).index()).css('left','-470px');
$('.list1 li').eq(prevIndex).animate({left:470},500);
}
$('.list1 li').eq($(this).index()).animate({left:0},500);
prevIndex=$(this).index();
},this),500)
})
})
</script>
</head>
<body>
<div id="wrap">
<ul class="list1">
<li><img src="images/1.jpg"></li>
<li><img src="images/2.jpg"></li>
<li><img src="images/3.jpg"></li>
<li><img src="images/4.jpg"></li>
<li><img src="images/5.jpg"></li>
</ul>
<ul class="list2">
<li class="active">1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ul>
</div>
</body>
</html>
相關文章
- jQuery輪播圖之上下輪播jQuery
- jQuery實現輪播效果jQuery
- jQuery Mobile圖片輪轉輪播jQuery
- 直播app開發,實現輪播圖上下自動滑動展示效果APP
- 用RecyclerView打造一個輪播圖View
- 縮放效果的輪播圖 iOSiOS
- PS教程:教你打造APP效果展示圖APP
- (轉)jquery實現圖片輪播jQuery
- 如何使用RecyclerView打造首頁輪播圖View
- JavaScript焦點圖輪播效果詳解JavaScript
- 原生JS實現輪播圖的效果JS
- java學習---前端---使用JavaScript和jQuery實現圖片輪播圖前端JavaScriptjQuery
- 淘寶關鍵詞搜尋介面,淘寶商品列表介面,淘寶商品銷量排序介面資料採集程式碼展示排序
- 淘寶API,按圖搜尋淘寶商品(拍立淘)API
- 打造萬能的BannerView(ViewPager)無限輪播圖Viewpager
- 用RecyclerView打造一個輪播圖(進階版)View
- js、jQuery實現文字上下無縫輪播、滾動效果JSjQuery
- 原生JS實現輪播圖--第一章圖片展示JS
- AndroidApp圖片輪播效果的元件化AndroidAPP元件化
- Axure實現輪播效果
- JavaScript字串動畫輪播效果JavaScript字串動畫
- 如何用JavaScript做出淘寶評星效果JavaScript
- 使用jQuery實現的平滑滾動輪播圖jQuery
- 直播app原始碼,HTML + jQuery 實現輪播圖APP原始碼HTMLjQuery
- JQuery實現圖片輪播無縫滾動jQuery
- jQuery-demos輪播圖練習(一)jQuery
- 一對一直播系統原始碼,軟體首頁輪播圖輪播效果原始碼
- 純CSS打造淘寶導航選單欄CSS
- Flutter輪播圖Flutter
- vue輪播圖Vue
- iOS 輪播圖iOS
- Android 和 iOS 圖片輪播AndroidiOS
- 淘寶API:淘寶/天貓獲得淘寶商品快遞費用API
- JS實現輪播圖效果(有詳細註釋)JS
- 直播app開發,首頁輪播圖效果實現APP
- javascript實現的焦點圖輪播效果詳解JavaScript
- jQuery實現3D圖片輪播詳解jQuery3D
- 圖靈淘寶商城圖書秒殺圖靈