一张图片点击鼠标放大,再点缩小基于jquery1.8.3实现,下面有个不错的示例,感兴趣的朋友可以参考下
复制代码 代码如下:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script src="https://www.jb51.net/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>
<img alt="" src="https://www.jb51.net/photos/image1.jpg" />
</div>
</div>
</body>
</html>
您可能感兴趣的文章: