手机
当前位置:查字典教程网 >编程开发 >Javascript教程 >基于jquery实现一张图片点击鼠标放大再点缩小
基于jquery实现一张图片点击鼠标放大再点缩小
摘要:复制代码代码如下:varisopen=false;varnewImg;varw=200;//将图片宽度+200varh=200;//将图片高...

复制代码 代码如下:

<!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">

<img id="img1" alt="" src="photos/image1.jpg" />

</div>

</div>

</body>

</html>

【基于jquery实现一张图片点击鼠标放大再点缩小】相关文章:

jQuery实现首页图片淡入淡出效果的方法

基于jquery实现下拉框美化特效

基于JavaScript实现图片点击弹出窗口而不是保存

Jquery实现动态切换图片的方法

jQuery实现鼠标经过图片变亮其他变暗效果

jquery实现图片左右切换的方法

jquery实现点击label的同时触发文本框点击事件的方法

jquery实现弹出层效果实例

jQuery实现在列表的首行添加数据

jQuery实现页面内锚点平滑跳转特效的方法总结

精品推荐
分类导航