亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

鼠標(biāo)放在圖片上顯示大圖的JS代碼

 更新時(shí)間:2013年03月26日 14:53:05   作者:  
將圖片查詢(xún)出來(lái)之后,還需要加一個(gè)查看大圖的功能,于是就用js寫(xiě)了一個(gè)方法,然后在image的onmouseover事件中調(diào)用此方法,這樣在鼠標(biāo)懸浮在小圖上面的時(shí)候,其大圖就會(huì)自動(dòng)的顯示出來(lái)。

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

復(fù)制代碼 代碼如下:

<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、寬和高都超過(guò)了,看誰(shuí)超過(guò)的多,誰(shuí)超的多就將誰(shuí)設(shè)置為最大值,其余策略按照2、3
        //2、如果寬超過(guò)了并且高沒(méi)有超,設(shè)置寬為最大值
        //3、如果寬沒(méi)超過(guò)并且高超過(guò)了,設(shè)置高為最大值

        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:

復(fù)制代碼 代碼如下:

<img id="img" src="http://chabaoo.cn/images/logo.gif" onmouseover="over(img,divImage,imgbig);" onmouseout="out()" width="100" alt="" height="100" />

    <%--顯示大圖標(biāo)的區(qū)域--%>
    <div id="divImage" style="display: none; left: 120px;top:5px; position: absolute">
        <img id="imgbig" src="http://chabaoo.cn/images/logo.gif" alt="預(yù)覽" />
    </div>

相關(guān)文章

最新評(píng)論