最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

javascript放大鏡效果的簡單實(shí)現(xiàn)

 更新時(shí)間:2013年12月09日 10:04:34   作者:  
這篇文章主要是對javascript放大鏡效果的簡單實(shí)現(xiàn)進(jìn)行了介紹,需要的朋友可以過來參考下,希望對大家有所幫助

這個(gè)效果并不難,要點(diǎn)是位置和比例設(shè)置,

捕獲鼠標(biāo)位置、判斷鼠標(biāo)位置區(qū)域、還有onmouseover事件、onmousemove事件、onmouseout事件

設(shè)置顯示大圖的比例,小圖上顯示的切圖比例都要弄準(zhǔn)確點(diǎn),最好是2倍啦,4倍啦。

主要注意寬度,我這里的圖片m.jpg是1440X900的....

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

<!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=utf-8">
<title>放大鏡效果</title>
<style type="text/css">
*{margin:0;padding:0;}
#smallimg{width:360px;float:left;position:relative;border:1px solid red;}
#smallimg img{ width:360px;}
#bigimg{float:left;width:400px;height:400px;margin-left:40px;border:1px solid #ccc;display:none;}
#showimg{width:100px;height:100px;background:#fff;cursor:move; position:absolute;border:1px solid #666;opacity:0.5;filter:alpha(opacity=50);display:none;}
</style>
</head>
<body>
<div id="smallimg">
 <img src="jq/m.jpg" alt=""/>
 <div id="showimg">&nbsp;</div>
</div>
<div id="bigimg">&nbsp;</div>


<script type="text/javascript">
var $=function(id){return typeof id=="string"?document.getElementById(id):id}
var smallimg = $("smallimg");
var showimg = $("showimg");//濾鏡圖片
var bigimg = $("bigimg");
var small_url = smallimg.getElementsByTagName("img")[0].getAttribute("src");
var show_half = maxWidth = maxHeight = 0;
smallimg.onmouseover = function(){
 showimg.style.display = "block";
 bigimg.style.display = "inline";
 show_half = showimg.offsetHeight/2;
 maxWidth = smallimg.clientWidth - showimg.offsetWidth;
 maxHeight = smallimg.clientHeight - showimg.offsetHeight;
 //上面兩個(gè)變量指明showimg允許活動的區(qū)域
};
smallimg.onmousemove = function(e){
 var e=window.event?window.event:e;
 var num=bigimg.clientWidth/showimg.clientWidth;
 var Top = e.clientY - smallimg.offsetTop - show_half;
 var Left = e.clientX - smallimg.offsetLeft - show_half;
 //獲取當(dāng)前移動的showimg位置 計(jì)算方法是 鼠標(biāo)坐標(biāo) - 最外面容器的坐標(biāo) - 盒子的寬(高)的/2
 Top = Top<0?0:Top>maxHeight?maxHeight:Top;
 Left = Left<0?0:Left>maxWidth?maxWidth:Left;
 showimg.style.top = Top + "px";
 showimg.style.left = Left + "px";
 bigimg.style.background = "url("+small_url+") -"+Left*num+"px -"+Top*num+"px no-repeat";
};
smallimg.onmouseout = function(){
 showimg.style.display="none";
 bigimg.style.background ="";
 bigimg.style.display="none"
};
</script>
</body>
</html>

相關(guān)文章

最新評論

辽阳县| 延津县| 同德县| 新河县| 阜平县| 海淀区| 阳新县| 翼城县| 台北县| 桂东县| 泉州市| 南丰县| 湖北省| 平江县| 乌审旗| 衢州市| 高碑店市| 大荔县| 金沙县| 资源县| 仪陇县| 苏尼特右旗| 郸城县| 罗江县| 衡南县| 罗源县| 沂水县| 墨竹工卡县| 巫溪县| 巴林左旗| 鄂伦春自治旗| 通河县| 南京市| 原平市| 盘山县| 顺义区| 新民市| 武乡县| 巴林左旗| 七台河市| 会同县|