上傳圖片之上傳後查看大圖

來源:互聯網
上載者:User

將圖片查詢出來之後,還需要加一個查看大圖的功能,於是就用js寫了一個方法,然後在image的onmouseover事件中調用此方法,這樣在滑鼠懸浮在小圖上面的時候,其大圖就會自動的顯示出來。


顯示大圖和隱藏大圖的js代碼:

 

<script type="text/javascript">   //顯示圖片   function over(imgid,obj,imgbig)   {//大圖顯示的最大尺寸  4比3的大小  400 300maxwidth=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" />            <%--顯示大表徵圖的地區--%>    <div id="divImage" style="display: none; left: 120px;top:5px; position: absolute">        <img id="imgbig" src="~/Images/noImage.gif" alt="預覽" />    </div>

 

簡單實用,歡迎交流。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.