基于jquery實(shí)現(xiàn)一張圖片點(diǎn)擊鼠標(biāo)放大再點(diǎn)縮小
更新時間:2013年09月29日 16:17:06 作者:
一張圖片點(diǎn)擊鼠標(biāo)放大,再點(diǎn)縮小基于jquery1.8.3實(shí)現(xiàn),下面有個不錯的示例,感興趣的朋友可以參考下
復(fù)制代碼 代碼如下:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script src="jquery-1.8.3.min.js"></script>
<script>
var isopen = false;
var newImg;
var w = 200; //將圖片寬度+200
var h = 200; // 將圖片高度 +200
$(document).ready(function(){
$("img").bind("click", function(){
newImg = this;
if (!isopen)
{
isopen = true;
$(this).width($(this).width() + w);
$(this).height($(this).height() + h);
moveImg(10, 10);
}
else
{
isopen = false;
$(this).width($(this).width() - w);
$(this).height($(this).height() - h);
moveImg(-10, -10);
}
});
});
//移位
i = 0;
function moveImg(left,top)
{
var offset = $(newImg).offset();
$(newImg).offset({ top: offset.top + top, left: offset.left + left});
if (i == 10)
{
i =0;
return;
}
setTimeout("moveImg("+left+","+top+")", 10);
i++;
}
</script>
</head>
<body>
<div id="imgBox" style="width:100px; height:100px; background:#cccccc">
<img id="img1" style="width:100px;height:100px; " alt="" src="photos/image1.jpg" />
</div>
</div>
</body>
</html>
您可能感興趣的文章:
相關(guān)文章
節(jié)點(diǎn)的插入之a(chǎn)ppend()和appendTo()的用法介紹
說到節(jié)點(diǎn)的插入想必大家對append()和appendTo()的用法并不陌生吧,下面有個不錯的是,希望對大家學(xué)習(xí)有所幫助2014-01-01
jQuery實(shí)現(xiàn)鼠標(biāo)滑動切換圖片
這篇文章主要為大家詳細(xì)介紹了jQuery實(shí)現(xiàn)鼠標(biāo)滑動切換圖片,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2020-05-05
jQuery解析XML文件同時動態(tài)增加js文件的方法
這篇文章主要介紹了jQuery解析XML文件同時動態(tài)增加js文件的方法,涉及jQuery Ajax調(diào)用及返回函數(shù)中增加js文件的相關(guān)使用技巧,需要的朋友可以參考下2015-06-06
jQuery學(xué)習(xí)筆記之jQuery構(gòu)建函數(shù)的7種方法
jQuery把所有的操作都包裝在一個jQuery()函數(shù)中,形成了統(tǒng)一(也是惟一)的操作入口,這為jQuery操作降低了門檻。那我們來看下具體構(gòu)造函數(shù)的“七種武器”吧。2014-06-06

