利用jQuery UI 实现图片局部放大

图示


与 “ 利用jQuery UI 实现图片部份截取 ”相同,只是代码微有调整

HTML
id="quen" 为截取框
id="c" 为整个图片框
id="e" 为截取后的框

< div  style ='width:732px;height:458px'  id ='c' >
    
< div  id ='quen'  style ='position:absolute;top:0px;left:0px;border:solid  2px blue;width:100px;height:100px' >
        
< div  id ='quen2'  style ='background:red;width:100%;height:100%' ></ div >
    
</ div >
    
< img  src ='1.jpg'  />
</ div >
< br />< br />< br />
< div  style ='position:absolute;overflow:hidden;width:200px;height:200px' >
    
< div  id ='e'  style ='position:relative;' >
        
< img  src ='1.jpg'  width ='1464'  height ='916' />
    
</ div >
</ div >

JS

$(function() {
    $(
" #quen2 " ) . css({opacity : 0 });  // 初始化移动框为透明
    $(
" #quen " ) . css({top : $( " #c img " ) . offset() . top , left : $( " #c img " ) . offset() . left})  // 移动框的初始位置放在图片顶部
    
. draggable({
        containment
: " parent " ,   // 只能在父元素中拖动
        drag
: function(e , ui){
            
// 动态改变取图框的位置
            $(
" #e " ) . css({left : " - " + ui . position . left * 2 + " px " , top : " - " + ui . position . top * 2 + " px " });
        }
    })
    
. resizable({
        handles
: " n,e,s,w,se,sw,ne,nw " ,
        minHeight
: 30 ,
        minWidth
: 30 ,
        maxHeight
: 458 ,
        maxWidth
: 732 ,
        resize
: function(e , ui){
            
// 动态改变图框的大小
            $(
" #e " ) . parent() . css({width : ui . size . width * 2 , height : ui . size . height * 2 });
        }
    });
});

结果演示

下载范例

转载于:https://www.cnblogs.com/fdszlzl/archive/2009/07/23/1529039.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值