JS、JQ、FancyZoom 插件,分别实现兼容IE和火狐图片缩小放大


  <script type="text/javascript"> 
  //兼容IE和火狐 缩小放大、缩放 
  function ImageSuofang(args) { 
  var oImg = document.getElementById("oImg"); 
  if (args) { 
  oImg.width = oImg.width * 1.1; 
  oImg.height = oImg.height * 1.1; 
  } 
  else { 
  oImg.width = oImg.width / 1.1; 
  oImg.height = oImg.height / 1.1; 
  } 
  }     
  </script> 

<form id="form1"> 

  <div class="pancontainer" data-orient="center" style="width:320px; height:480px;margin: 5px 300px 0px 400px;border: 1px solid #000;"> 
<img id="oImg" src="F:\照片\表情\bf096b63f6246b60ae162428e8f81a4c510fa256.jpg" alt="pic"/> 
</div> 

  <input id="btn1" type="button" value="放大" οnclick="ImageSuofang(true)" /> 
  <input id="btn2" type="button" value="缩小" οnclick="ImageSuofang(false)" /> 
  <!-- <input type="button" value="<-Rotate逆时针" name="RotateL" id="RotateL" οnclick="rotateRight('oImg',90);"> --> 


</form>

通过JS实现 通讯录的照片放大 缩小 

var img='<div id="photoFrame" style="width:100%; height:auto;border:0px;text-align:center"> '+"<img id='myImg' src=/webrdp-web/systemQuery.do?action=downloadAtt&fileId="+fileId+"" + "></div>";
  $("#PHOTO").html(img);

  var oPhoto= document.getElementById("photoFrame");
  var oImg = document.getElementById("myImg");
       oImg.onclick =function(){
  var height= oImg.height;
  if(height<=120){
  oImg.width = 150;
//oImg.width = oImg.width * 2.1;
  oImg.height = 220;
  oPhoto.height = 220;
  }
  else {
  oImg.width = 98;
  oImg.height = 120;
  oPhoto.height = 120;
  }
}  
通过JQ方法实现照片放大缩小
<script type="text/javascript">
  $(function(){
  $("#img1").click(function(){
  var width = $(this).width();
  if(width==100)
  {
  $(this).width(200);
  $(this).height(300);
  }
  else
  {
  $(this).width(100);
  $(this).height(150);
  }
  });
  });
  </script>
使用FancyZoom 插件 实现照片的放大缩小

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<script src="js-global/FancyZoom.js" language="JavaScript" type="text/javascript"></script>
<script src="js-global/FancyZoomHTML.js" language="JavaScript" type="text/javascript"></script>
</head>
<body onLoad="setupZoom();">
<a href="http://49.74.217.106:48088//webrdp-web/systemQuery.do?action=downloadAtt&fileId=53192735-08ac-44f7-9bff-0537c483303e"><img src="http://49.74.217.106:48088/webrdp-web/systemQuery.do?action=downloadAtt&fileId=53192735-08ac-44f7-9bff-0537c483303e" width="161" height="123" border="0" alt="" id="img-mwsf-9" class="photo" /></a>
放大时动作流畅,简单实用,适合在本窗口点击察看大图 <br>
<br>
<div align="center"> <br>
  <br>
  更多JS代码下载请访问icodeku.com <a href="http://www.icodeku.com">http://www.icodeku.com</a> </div>
</body>
<script>
</script>
</html>

插件文件如下:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在前端开发中,可以使用原生 JavaScript 或 jQuery 来实现图片放大效果。下面分别给出两种方法: 1. 原生 JavaScript 方法: ```javascript // HTML 结构 // <img src="path_to_image.jpg" alt="Image" class="zoomable-image"> // CSS 样式 // .zoomable-image { // cursor: pointer; // } // JavaScript 代码 const images = document.querySelectorAll('.zoomable-image'); images.forEach(image => { image.addEventListener('click', function() { // 创建放大图片的容器 const zoomContainer = document.createElement('div'); zoomContainer.classList.add('zoom-container'); document.body.appendChild(zoomContainer); // 创建放大图片 const zoomedImage = document.createElement('img'); zoomedImage.src = this.src; zoomedImage.alt = this.alt; zoomContainer.appendChild(zoomedImage); // 点击放大图片容器时关闭放大效果 zoomContainer.addEventListener('click', function() { this.remove(); }); }); }); ``` 2. 使用 jQuery 方法: ```javascript // HTML 结构与 CSS 样式同上 // JavaScript 代码 $('.zoomable-image').on('click', function() { // 创建放大图片的容器 const zoomContainer = $('<div>').addClass('zoom-container'); $('body').append(zoomContainer); // 创建放大图片 const zoomedImage = $('<img>').attr('src', this.src).attr('alt', this.alt); zoomContainer.append(zoomedImage); // 点击放大图片容器时关闭放大效果 zoomContainer.on('click', function() { $(this).remove(); }); }); ``` 以上代码实现了点击图片时,在页面上创建一个放大图片,并且点击放大图片时可以关闭放大效果。你可以根据实际需求,对样式和交互进行进一步的调整和优化。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值