CSS+DIV實現圖片動態顯示(完美版)

來源:互聯網
上載者:User

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

<title>Show Photo</title>

<script type="text/javascript" language="javascript">

   function ImageDivMouseOver(obj)

   {

        document.getElementById(obj).style.left=window.event.x+15+document.documentElement.scrollLeft;

        document.getElementById(obj).style.top=window.event.y+15+document.documentElement.scrollTop;

   }

</script>

<style type="text/css">

.showImage a{

display:block;/**//*讓連結以塊狀呈現,這樣不用點中連結文字就可以響應連結*/

}

.showImage a img{

display: none; visibility:hidden;/**//*初始化資訊面板不顯示*/

}

.showImage a:hover{_border:none;text-decoration:none;}/**//*IE7以下版本A狀態偽類bug*/

.showImage a:hover img{

display:block;

visibility:visible;

position: absolute;

display:block;

width: 139px;/**//*只給出寬度,高讓它隨內容多少自動調整*/

border: 1px solid rgb(91,185,233);

background-color: rgb(228,246,255);

z-index:999;/**//*把資訊面板提到一個較高的位置,使連結文字過長時不會與面板重疊,但這隻對FF有效*/

}

.showImage a img{

border:none;/**//*去除圖片邊框,預設情況下,連結內的圖片在標準瀏覽器會出現邊框*/

display:block;

position: absolute;/**//*用絕對位置抽離正常文字資料流,不然在設計的時候考慮到不同瀏覽器正常顯示會更麻煩*/

left:80px;

top:30px;

}

.imgStyle{z-index:10px; position:absolute}

</style>

</head>

<body>

<form>

<div style="height:700px;"></div>

    <div class="showImage"><a href="#" onmouseover="ImageDivMouseOver('img1')">第一個圖片顯示連結<img id="img1" src="http://hiphotos.baidu.com/木合達/pic/item/30392594485a1413d21b70c9.jpg" class="imgStyle"></img></a>

    <br />

    <a href="#" onmouseover="ImageDivMouseOver('img2')" >第二個圖片顯示連結<img id="img2" src="http://hiphotos.baidu.com/木合達/pic/item/30392594485a1413d21b70c9.jpg" class="imgStyle"/></a>

    <br />

    <a href="#" onmouseover="ImageDivMouseOver('img3')" >第三個圖片顯示連結<img id="img3" src="http://hiphotos.baidu.com/木合達/pic/item/30392594485a1413d21b70c9.jpg" class="imgStyle"/></a></div>

</form>

</body>

</html>

最佳化內容:

1.跟隨滑鼠

2.增加考慮捲軸因素

3.圖片最前位置顯示

相關文章

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.