基于jQuery實現(xiàn)照片墻自動播放特效
更新時間:2017年01月12日 16:47:09 作者:maskice
這篇文章主要為大家詳細介紹了基于jQuery實現(xiàn)照片墻自動播放特效,具有一定的參考價值,感興趣的小伙伴們可以參考一下
一個動態(tài)展示圖片的頁面:
功能:定時從后臺取數(shù)據(jù),進行頁面圖片追加。對已經(jīng)在頁面中的圖片,進行放大縮小動畫展示。目前我們用于微信新關注用戶頭像展示。
<html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" /> <title>抽獎</title> <script src="../../js/jquery-1.7.2.min.js"></script> <style> body{ background-color:#000; text-transform:uppercase; color:#fff; position: relative; } .img{ float:left; margin:2px; cursor:pointer; opacity:0.4; filter:progid:DXImageTransform.Microsoft.Alpha(opacity=40); width : 60px; height : 60px; } .bigpic { position: absolute; overflow: hidden; z-index: 99; } .bigpic img { width: 100%;opacity:1; } </style> </head> <body> <div class="bigpic" style="display: none;"> <img class="bigimg" src="" /> </div> <div id="content" style="position: absolute;border:0;padding:0;margin-top: 10px;" > <!-- <img src="images/1.jpg" class="img" /> <img src="images/2.jpg" class="img" /> <img src="images/1.jpg" class="img" /> <img src="images/2.jpg" class="img" /> <img src="images/1.jpg" class="img" /> <img src="images/2.jpg" class="img" /> <img src="images/1.jpg" class="img" /> <img src="images/2.jpg" class="img" /> <img src="images/1.jpg" class="img" /> <img src="images/2.jpg" class="img" /> <img src="images/1.jpg" class="img" /> <img src="images/1.jpg" class="img" /> <img src="images/1.jpg" class="img" /> <img src="images/1.jpg" class="img" /> <img src="images/1.jpg" class="img" /> <img src="images/1.jpg" class="img" /> <img src="images/1.jpg" class="img" /> <img src="images/1.jpg" class="img" /> <img src="images/1.jpg" class="img" /> <img src="images/1.jpg" class="img" /> <img src="images/1.jpg" class="img" /> <img src="images/1.jpg" class="img" /> <img src="images/1.jpg" class="img" /> <img src="images/1.jpg" class="img" /> <img src="images/1.jpg" class="img" /> <img src="images/1.jpg" class="img" /> <img src="images/1.jpg" class="img" /> <img src="images/1.jpg" class="img" /> <img src="images/1.jpg" class="img" /> <img src="images/1.jpg" class="img" /> <img src="images/1.jpg" class="img" /> <img src="images/1.jpg" class="img" /> --> </div> <script type="text/javascript"> var t1 ;//= window.setTimeout(loadUser,1000); //var t1 = window.setInterval(time,6000); var idx = 0; var maxNum = 0; var maxId = 0; var minId = 0; var isBegin = 1; var url = "http://網(wǎng)址"; function loadUser(){ $("#begin").css('display','none'); $.post("../../servlet/draw", { type : "messageList", limit : 2, maxId : maxId, isBegin : isBegin, time : new Date() }, function(data,status){ var jsonobj=eval('('+data+')'); if(jsonobj.code=="200"){ isBegin = 0; var jsonarr = jsonobj.list; for(var i=0;i<jsonarr.length;i++){ var himg = jsonarr[i].headImg; if(himg==''){ himg = "/activity/draw/images/1.jpg"; } $("#content").prepend('<img src="'+url+jsonarr[i].headImg+'" class="img" />'); if(minId==0){ minId = jsonarr[i].id; } maxId = jsonarr[i].id; maxNum = maxNum + 1; if(idx!=0) idx=idx+1; } //console.log("maxNum:"+maxNum); t1 = window.setTimeout(time,1000); } }); } function time(){ idx=idx+1; var i = 1; $(".img").each(function(){ var imgurl = $(this).attr("src"); //console.log(idx+" "+$(this).position().left); if(i == idx){ $(this).css("opacity",1); //if(i==3){ // $("#content").prepend('<img src="images/2.jpg" class="img" />'); // idx=idx+1; //} $(".bigimg").attr({ "src": imgurl }); var bwidth = $(".bigimg").width(); var bheight = $(".bigimg").height(); var picleft = $(this).position().left; var pictop = $(this).position().top; var pic = $(this); //console.log(idx+" "+bwidth+" "+bheight+" "+$(this).position().left+" "+$(this).position().top); var o = { left: "50%", width: "600px", height: "600px", top: "50px", "margin-left": "-300px" }; $(".bigpic").width(60); $(".bigpic").height(60); $(".bigpic").css({ "left": $(this).position().left, "top": $(this).position().top}); $(".bigpic").show(); $(".bigpic").animate(o, 2000, function () { setTimeout(function () { $(".bigpic").animate({ width: "60px", left: pic.position().left, top: pic.position().top, "margin-left": "0", "margin-top": "0" }, 2000, function () { //$(".bigpic").fadeOut(2000, function () { $(".bigpic").hide(); //t1 = setTimeout(time, 1000); loadUser(); }); }, 2000) }); }else{ $(this).css("opacity",0.4); } i++; }); if(maxNum == idx) idx = 0; } loadUser(); </script> </body> </html>
界面截圖:
參考:http://xiazai.jb51.net/201701/yuanma/jqueryphoto(jb51.net).rar
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
jQuery EasyUI的TreeGrid查詢功能實現(xiàn)方法
這篇文章主要介紹了jQuery EasyUI的TreeGrid查詢功能實現(xiàn)方法,需要的朋友可以參考下2017-08-08jQuery實現(xiàn)右側顯示可向左滑動展示的深色QQ客服效果代碼
這篇文章主要介紹了jQuery實現(xiàn)右側顯示可向左滑動展示的深色QQ客服效果代碼,涉及jQuery控制頁面元素樣式動態(tài)變換的實現(xiàn)技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-10-10jQuery Pagination分頁插件_動力節(jié)點Java學院整理
此jQuery插件為Ajax分頁插件,一次性加載,故分頁切換時無刷新與延遲,如果數(shù)據(jù)量較大不建議用此方法,因為加載會比較慢。下面通過本文給大家分享jQuery Pagination分頁插件的使用方法及參數(shù)介紹,感興趣的朋友一起看看吧2017-07-07jquery的attr方法禁用表單元素禁用輸入內(nèi)容
這篇文章主要介紹了通過jquery的attr方法來禁用表單元素禁輸入內(nèi)容,示例如下,需要的朋友可以參考參考2014-06-06