js寫的方法實現(xiàn)上傳圖片之后查看大圖
更新時間:2014年03月05日 17:17:52 作者:
用js寫了一個方法,然后在image的onmouseover事件中調(diào)用此方法,這樣在鼠標懸浮在小圖上面的時候,其大圖就會自動的顯示出來
將圖片查詢出來之后,還需要加一個查看大圖的功能,于是就用js寫了一個方法,然后在image的onmouseover事件中調(diào)用此方法,這樣在鼠標懸浮在小圖上面的時候,其大圖就會自動的顯示出來。
顯示大圖和隱藏大圖的js代碼:
<script type="text/javascript">
//顯示圖片
function over(imgid,obj,imgbig)
{
//大圖顯示的最大尺寸 4比3的大小 400 300
maxwidth=400;
maxheight=300;
//顯示
obj.style.display="";
imgbig.src=imgid.src;
//1、寬和高都超過了,看誰超過的多,誰超的多就將誰設置為最大值,其余策略按照2、3
//2、如果寬超過了并且高沒有超,設置寬為最大值
//3、如果寬沒超過并且高超過了,設置高為最大值
if(img.width>maxwidth&&img.height>maxheight)
{
pare=(img.width-maxwidth)-(img.height-maxheight);
if(pare>=0)
img.width=maxwidth;
else
img.height=maxheight;
}
else if(img.width>maxwidth&&img.height<=maxheight)
{
img.width=maxwidth;
}
else if(img.width<=maxwidth&&img.height>maxheight)
{
img.height=maxheight;
}
}
//隱藏圖片
function out()
{
document.getElementById('divImage').style.display="none";
}
</script>
顯示小圖的image和顯示大圖的image:
<img id="img" src="你的圖片地址" onmouseover="over(img,divImage,imgbig);" onmouseout="out()" width="100" alt="" height="100" />
<%--顯示大圖標的區(qū)域--%>
<div id="divImage" style="display: none; left: 120px;top:5px; position: absolute">
<img id="imgbig" src="~/Images/noImage.gif" alt="預覽" />
</div>
顯示大圖和隱藏大圖的js代碼:
復制代碼 代碼如下:
<script type="text/javascript">
//顯示圖片
function over(imgid,obj,imgbig)
{
//大圖顯示的最大尺寸 4比3的大小 400 300
maxwidth=400;
maxheight=300;
//顯示
obj.style.display="";
imgbig.src=imgid.src;
//1、寬和高都超過了,看誰超過的多,誰超的多就將誰設置為最大值,其余策略按照2、3
//2、如果寬超過了并且高沒有超,設置寬為最大值
//3、如果寬沒超過并且高超過了,設置高為最大值
if(img.width>maxwidth&&img.height>maxheight)
{
pare=(img.width-maxwidth)-(img.height-maxheight);
if(pare>=0)
img.width=maxwidth;
else
img.height=maxheight;
}
else if(img.width>maxwidth&&img.height<=maxheight)
{
img.width=maxwidth;
}
else if(img.width<=maxwidth&&img.height>maxheight)
{
img.height=maxheight;
}
}
//隱藏圖片
function out()
{
document.getElementById('divImage').style.display="none";
}
</script>
顯示小圖的image和顯示大圖的image:
復制代碼 代碼如下:
<img id="img" src="你的圖片地址" onmouseover="over(img,divImage,imgbig);" onmouseout="out()" width="100" alt="" height="100" />
<%--顯示大圖標的區(qū)域--%>
<div id="divImage" style="display: none; left: 120px;top:5px; position: absolute">
<img id="imgbig" src="~/Images/noImage.gif" alt="預覽" />
</div>
相關文章
在JS中a標簽加入單擊事件屏蔽href跳轉(zhuǎn)頁面
這篇文章主要介紹了JS中a標簽加入單擊事件屏蔽href跳轉(zhuǎn)頁面的相關資料,需要的朋友可以參考下2016-12-12原生js實現(xiàn)仿window10系統(tǒng)日歷效果的實例
下面小編就為大家?guī)硪黄鷍s實現(xiàn)仿window10系統(tǒng)日歷效果的實例。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-10-10基于javascript實現(xiàn)頁面加載loading效果
這篇文章主要為大家詳細介紹了基于javascript實現(xiàn)頁面加載loading效果的相關資料,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-03-03仿google adsense顏色選擇器代碼,從中易廣告聯(lián)盟程序提取
仿google adsense顏色選擇器代碼,從中易廣告聯(lián)盟程序提取...2007-11-11