JS實(shí)現(xiàn)的仿QQ空間圖片彈出效果代碼
本文實(shí)例講述了JS實(shí)現(xiàn)的仿QQ空間圖片彈出效果代碼。分享給大家供大家參考,具體如下:
<script type="text/javascript">
function imageShow(which_click) {
var image_path = which_click;
//alert(image_path);
var tag_top = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
//創(chuàng)建底層灰色DIV
var index_tag = document.createElement("div");
index_tag.style.cssText = "width:100%;height:"+Math.max(document.body.clientHeight,document.body.offsetHeight,document.documentElement.clientHeight)+"px;position:relative;background:black;top:0;filter: Alpha(Opacity=80);Opacity:0.8;";
document.body.appendChild(index_tag);
//index_tag.ondblclick = closeIndexTag;
index_tag.onclick = closeIndexTag;
//創(chuàng)建圖片DIV
var img_tag = document.createElement("div");
img_tag.style.cssText = "font:12px/18px verdana;overflow:auto;text-align:center;position:absolute;width:200px;border:5px solid white;background:white;color:white;left:"+(parseInt(document.body.offsetWidth)/2-100)+"px;top:"+(document.documentElement.clientHeight/3+tag_top)+"px;";
img_tag.innerHTML = "<div style='padding:10px;background:#cccccc;border:1px solid white'><img src='images/loading.gif' /><br /><br /><b style='color:#999999;font-weight:normal'>Image loading...</b><br /></div>";
img_tag.oncontextmenu = function() {
var clsOK=confirm("是否確定關(guān)閉圖片顯示");
if(clsOK)
closeIndexTag();
return false;
}
img_tag.onclick = closeIndexTag;
//img_tag.onmousemove = barDidplay;
document.body.appendChild(img_tag);
//構(gòu)建圖片關(guān)閉按鈕
var close_tag = document.createElement("div");
close_tag.style.cssText = "display:none;position:absolute;left:10px;top:10px;color:black;";
close_tag.innerHTML = "<b style='background:none;border:0px solid white;filter:Alpha(Opacity=50);Opacity:0.5;cursor:pointer;'> 關(guān)閉 </b>";
close_tag.onclick = closeIndexTag;
var img = new Image();
img.src = image_path;
img.style.cssText = "border:1px solid #cccccc;filter: Alpha(Opacity=0);Opacity:0;cursor:pointer";
img.onload = imgOK();
function imgOK() {
var temp = 0;
var stop_x = false;
var stop_y = false;
var img_tag_x = img_tag.offsetWidth;
var img_tag_y = img_tag.offsetHeight;
var img_x = img.width;
var img_y = img.height;
var scroll_x=document.documentElement.clientWidth;
var scroll_y=window.innerHeight||document.documentElement.clientHeight;
var yy = 0;
var xx = 0;
if(img_y > scroll_y || img_x > scroll_x){
yy = scroll_y - 100;
xx = (img_x / img_y) * yy;
}else{
xx = img_x + 4;
yy = img_y + 3;
}
img.style.width=xx-4+'px';
img.style.height=yy-3+'px';
var maxTime = setInterval(function() {
temp += 30;
if((img_tag_x + temp) < xx) {
img_tag.style.width = (img_tag_x + temp) + "px";
img_tag.style.left = (scroll_x - img_tag_x - temp)/2 + "px";
} else {
stop_x = true;
img_tag.style.width = xx + "px";
img_tag.style.left = (scroll_x - xx)/2 + "px";
}
if((img_tag_y + temp) < yy) {
img_tag.style.height = (img_tag_y + temp) + "px";
img_tag.style.top = (tag_top + (scroll_y - img_tag_y - temp)/2) + "px";
} else {
stop_y = true;
img_tag.style.height = yy + "px";
img_tag.style.top = (tag_top + (scroll_y - yy)/2) + "px";
}
if(stop_x && stop_y) {
clearInterval(maxTime);
img_tag.appendChild(img);
temp = 0;
imgOpacity(temp);
}
}, 1);
img_tag.innerHTML="";
img_tag.appendChild(close_tag);
}
function closeIndexTag() {
document.body.removeChild(index_tag);
document.body.removeChild(img_tag);
}
function imgOpacity(temp_imgOpacity) {
var temp = temp_imgOpacity;
temp += 10;
img.style.filter = "alpha(opacity=" + temp + ")";
img.style.opacity = temp/100;
var imgTime = setTimeout(function() {imgOpacity(temp);}, 10);
if(temp > 100)
clearTimeout(imgTime);
}
var bar_show;
function barDidplay(){
clearTimeout(bar_show);
close_tag.style.display = "block";
bar_show = setTimeout(function() {close_tag.style.display = "none"}, 1000);
}
}
</script>
html部分:
<a class="add" href="javascript:;" onclick="imageShow('img/hn_bg.jpg')">
<span>圖片效果</span>
</a>
更多關(guān)于JavaScript相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《JavaScript查找算法技巧總結(jié)》、《JavaScript動(dòng)畫特效與技巧匯總》、《JavaScript錯(cuò)誤與調(diào)試技巧總結(jié)》、《JavaScript數(shù)據(jù)結(jié)構(gòu)與算法技巧總結(jié)》、《JavaScript遍歷算法與技巧總結(jié)》及《JavaScript數(shù)學(xué)運(yùn)算用法總結(jié)》
希望本文所述對(duì)大家JavaScript程序設(shè)計(jì)有所幫助。
- 原生JS仿QQ閱讀點(diǎn)擊展開、收起效果
- js實(shí)現(xiàn)仿qq消息的彈出窗效果
- JS實(shí)現(xiàn)超簡(jiǎn)單的仿QQ折疊菜單效果
- JS實(shí)現(xiàn)仿QQ面板的手風(fēng)琴效果折疊菜單代碼
- js實(shí)現(xiàn)帶緩沖效果的仿QQ面板折疊菜單代碼
- JS實(shí)現(xiàn)仿QQ聊天窗口抖動(dòng)特效
- 純js實(shí)現(xiàn)仿QQ郵箱彈出確認(rèn)框
- 基于zepto.js實(shí)現(xiàn)仿手機(jī)QQ空間的大圖查看組件ImageView.js詳解
- javascript仿qq界面的折疊菜單實(shí)現(xiàn)代碼
- js設(shè)置控件的隱藏與顯示的兩種方法
- js菜單點(diǎn)擊顯示或隱藏效果的簡(jiǎn)單實(shí)例
- javascript 控制 html元素 顯示/隱藏實(shí)現(xiàn)代碼
- JS實(shí)現(xiàn)的模仿QQ頭像資料卡顯示與隱藏效果
相關(guān)文章
javascript 中設(shè)置window.location.href跳轉(zhuǎn)無(wú)效問(wèn)題解決辦法
這篇文章主要介紹了javascript 中設(shè)置window.location.href跳轉(zhuǎn)無(wú)效問(wèn)題解決辦法的相關(guān)資料,需要的朋友可以參考下2017-02-02
JavaScript中使用ActiveXObject操作本地文件夾的方法
以前一直用vbscript來(lái)操作文件夾,才發(fā)現(xiàn)原來(lái)使用JavaScript也是可以的,肯定不如vbs用的簡(jiǎn)單,不過(guò)學(xué)習(xí)一下還是不錯(cuò)的2014-03-03
如何在webpack項(xiàng)目中調(diào)試loader插件
最近在學(xué)習(xí)webpack,本文主要介紹了loader插件的調(diào)試方法,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-06-06
微信小程序云開發(fā)實(shí)現(xiàn)數(shù)據(jù)添加、查詢和分頁(yè)
這篇文章主要為大家詳細(xì)介紹了微信小程序云開發(fā)實(shí)現(xiàn)數(shù)據(jù)添加、查詢和分頁(yè),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-05-05
JavaScript中函數(shù)聲明與函數(shù)表達(dá)式的區(qū)別詳解
可能很多朋友只知道兩種聲明方式一個(gè)是函數(shù)聲明一個(gè)是函數(shù)表達(dá)式,具體有什么不同沒能說(shuō)得很好。事實(shí)上,JavaScript的解析器對(duì)函數(shù)聲明與函數(shù)表達(dá)式并不是一視同仁地對(duì)待的。下面看看這兩者到底有什么不同。2016-08-08
JavaScript數(shù)組和對(duì)象的復(fù)制
本篇文章主要介紹了JavaScript數(shù)組和對(duì)象的復(fù)制的相關(guān)知識(shí)。具有很好的參考價(jià)值。下面跟著小編一起來(lái)看下吧2017-03-03
如何獲取select下拉框的值(option沒有及有value屬性)
獲取select下拉框的值分為option沒有value屬性及有value屬性時(shí)的兩種情況,下面分別給出具體的實(shí)現(xiàn)代碼,需要的朋友可以參考下2013-11-11
JavaScript Rxjs mergeMap 的使用場(chǎng)合
這篇文章主要介紹了JavaScript Rxjs mergeMap 的使用場(chǎng)合,mergeMap 接收一個(gè)函數(shù)作為輸入?yún)?shù),這個(gè)函數(shù)的輸入?yún)?shù)就是通過(guò) pipe 鏈接 mergeMap 的 Observable 里包含的元素2022-07-07

