zoom插件实现图片放大缩小功能

不多说,上代码


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/

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值