源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

基于jquery实现一张图片点击鼠标放大再点缩小

  • 时间:2022-08-10 05:22 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:基于jquery实现一张图片点击鼠标放大再点缩小
[u]复制代码[/u] 代码如下:
<!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>
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部