欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

鼠標(biāo)滑上去后圖片放大浮出效果的js代碼

 更新時間:2011年05月28日 00:14:46   作者:  
用javascript做了一個鼠標(biāo)滑上去后圖片放大浮出的效果,大家指正一下。
復(fù)制代碼 代碼如下:

<script>
function GetAbsPosition(obj)
{
var curleft = 0, curtop = 0;
do {
curleft += obj.offsetLeft;
curtop += obj.offsetTop;
} while (obj = obj.offsetParent);
return [curleft,curtop];
}
function ShowFloatingImage(image, width, height)
{
var id = "trailimageid";
var newdiv = document.getElementById(id);
if(newdiv == null)
{
newdiv = document.createElement('div');
newdiv.setAttribute('id',id);
newdiv.setAttribute('onmouseout', "HideElement('"+id+"');");
document.body.appendChild(newdiv);
}
newdiv.innerHTML = '<img src='+image.src+ ' width='+(image.width + width) + ' height=' + (image.height + height) + ' />';
var absPos = GetAbsPosition(image);
newdiv.style.position = "absolute";
newdiv.style.posLeft = absPos[0] - width/2;
newdiv.style.posTop = absPos[1] - height/2;
newdiv.style.display="block";
}
function HideElement(id)
{
var elem = document.getElementById(id);
elem.style.display="none";
}
</script>

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

<body>
<img src="1.jpg" width="300" height="300" onmouseover="ShowFloatingImage(this, 150, 150);" />
</body>

經(jīng)測試事件處理的不是很好。導(dǎo)致鼠標(biāo)移開不能回到原位。

相關(guān)文章

最新評論