zoom插件实现图片放大缩小功能
2016-09-03 14:00
726 查看
不多说,上代码
js代码
html页面代码
在上面的js代码中,可以放置项目本身图片,也可以放置远程图片,从远程读入图片的代码和下载图片,以及从服务器本地与项目本地读取图片是同一个性质,都是通过流传输然后对文件进行处理
controller层代码:同下载
参考网址:http://www.html580.com/9995/
js代码
<script src="app/js/zoom/js/e-smart-zoom-jquery.min.js"></script> <script> $(document).ready(function() { var imgv = $('<img id="imageFullScreen" src="rest/receiveStuff/queryImg?num='+parseInt(1000*Math.random())+'&type=sjzl&fileName=/'+surveycaselsh+'/'+img.name +'" />') $('#imgContainer').append(imgv); $('#imageFullScreen').smartZoom({'containerClass':'zoomableContainer'}); $('#topPositionMap,#leftPositionMap,#rightPositionMap,#bottomPositionMap').bind("click", moveButtonClickHandler); $('#zoomInButton,#zoomOutButton').bind("click", zoomButtonClickHandler); function zoomButtonClickHandler(e){ var scaleToAdd = 0.8; if(e.target.id == 'zoomOutButton') scaleToAdd = -scaleToAdd; $('#imageFullScreen').smartZoom('zoom', scaleToAdd); } function moveButtonClickHandler(e){ var pixelsToMoveOnX = 0; var pixelsToMoveOnY = 0; switch(e.target.id){ case "leftPositionMap": pixelsToMoveOnX = 50; break; case "rightPositionMap": pixelsToMoveOnX = -50; break; case "topPositionMap": pixelsToMoveOnY = 50; break; case "bottomPositionMap": pixelsToMoveOnY = -50; break; } $('#imageFullScreen').smartZoom('pan', pixelsToMoveOnX, pixelsToMoveOnY); } }); </script>
html页面代码
<div id="str" style="height:500px"> <div id="pageContent" style="width:8%;height:500px;float:left;padding:0 0 0 0;background:#556B2F"> <div id="positionButtonDiv"> <p> <span> <img id="zoomInButton" class="zoomButton" src="app/js/zoom/assets/zoomIn.png" title="zoom in" alt="zoom in" /> <img id="zoomOutButton" class="zoomButton" src="app/js/zoom/assets/ZoomOut.png" title="zoom out" alt="zoom out" /> </span> </p> <p><span class="positionButtonSpan"> <map name="positionMap" class="positionMapClass"> <area id="topPositionMap" shape="rect" coords="20,0,40,20" title="move up" alt="move up"/> <area id="leftPositionMap" shape="rect" coords="0,20,20,40" title="move left" alt="move left"/> <area id="rightPositionMap" shape="rect" coords="40,20,60,40" title="move right" alt="move right"/> <area id="bottomPositionMap" shape="rect" coords="20,40,40,60" title="move bottom" alt="move bottom"/> </map> <img src="app/js/zoom/assets/position.png" usemap="#positionMap" /> </span> </p> </div> </div> <div id="imgContainer" style="width:92%;height:100%;float:left"> <!-- <img id="imageFullScreen" src="f"/> --> </div> </div>
在上面的js代码中,可以放置项目本身图片,也可以放置远程图片,从远程读入图片的代码和下载图片,以及从服务器本地与项目本地读取图片是同一个性质,都是通过流传输然后对文件进行处理
var imgv = $('<img id="imageFullScreen" src="rest/receiveStuff/queryImg?num='+parseInt(1000*Math.random())+'&type=sjzl&fileName=/'+surveycaselsh+'/'+img.name +'" />')这段话放置了远程调用图片的url
controller层代码:同下载
@RequestMapping("/queryImg") @ResponseBody public Map<String,Object> queryImg(String type,String fileName,HttpServletResponse response){ OutputStream out = null; InputStream input = null; try{ URL url = new URL(ftputil.getFtpPath(new Ftp(type), fileName)); input = url.openStream(); response.setContentType("application/octet-stream"); response.setHeader("Content-Disposition","attachment; filename="+fileName); out = response.getOutputStream(); int i = 0; byte[] buffer = new byte[2048]; while((i = input.read(buffer)) != -1){ out.write(buffer,0,i); } out.flush(); input.close(); }catch(Exception e){ throw new SurveyServiceException("文件读取异常,详细请看日志", e); }finally{ if(out != null){ try { out.close(); } catch (IOException e) { throw new SurveyServiceException("文件读取异常,详细请看日志", e); } } if(input != null){ try { input.close(); } catch (IOException e) { throw new SurveyServiceException("文件读取异常,详细请看日志", e); } } } return null; }
参考网址:http://www.html580.com/9995/
相关文章推荐
- Android编程实现图片放大缩小功能ZoomControls控件用法实例
- jquery实现页面图片等比例放大缩小功能
- Javascript实现图片的移动,图片的放大,图片缩小功能
- Android 图片浏览功能简单实现(画廊效果实现,支持放大缩小)
- Android多点触控技术,实现对图片的放大缩小平移,惯性滑动等功能
- Android App中实现可以双击放大和缩小图片功能的实例
- JS、JQ、FancyZoom 插件,分别实现兼容IE和火狐图片缩小放大
- 利用jQuery插件imgAreaSelect实现图片上传裁剪(放大缩小)
- H5 Pinchzoom.js 插件实现手指触摸图片放大缩小
- 疯狂猜图中的图片放大缩小功能的实现
- jq实现鼠标移动到 图片上放大,移开图片缩小效果(打算封装成插件)
- jQuery插件zoom实现图片全屏放大弹出层特效
- highchart实现放大缩小zoom功能(转…
- Android多点触控技术,实现对图片的放大缩小平移,惯性滑动等功能
- 利用js简单实现图片的放大缩小功能
- Qt 图片浏览器 实现图片的放大缩小翻转等功能
- 用HTML5实现鼠标滚轮事件放大缩小图片的功能
- 基于RxPaparazzo实现图片裁剪、图片旋转、比例放大缩小功能
- Android多点触控技术,实现对图片的放大缩小平移,惯性滑动等功能