百度空间 | 百度首页 
 
查看文章
 
jquery 插件---图片区域选择,常用作裁剪图像
2008年11月14日 星期五 00:14

可以到这个网站:http://odyniec.net/projects/imgareaselect/

另外附上一个例子:http://gravatar.com ,他的图像裁剪使用了这个插件,效果很不错!

他是这么用的:

<script type="text/javascript">
   function preview (img, selection) {
    grav.cropper = { img: img, selection: selection }
    preview1(img, selection);
    preview2(img, selection);
   }
   function preview1 (img, selection) {
    var scaleX = 80 / selection.width;
    var scaleY = 80 / selection.height;
    $('#preview1').css({
     width: Math.round(scaleX * $('#cropimage').width()) + 'px',
     height: Math.round(scaleY * $('#cropimage').height()) + 'px',
     marginLeft: '-' + Math.round(scaleX * selection.x1) + 'px',
     marginTop: '-' + Math.round(scaleY * selection.y1) + 'px'
    });
   }
   function preview2 (img, selection) {
    var scaleX = 192 / selection.width;
    var scaleY = 192 / selection.height;
    $('#preview2').css({
     width: Math.round(scaleX * $('#cropimage').width()) + 'px',
     height: Math.round(scaleY * $('#cropimage').height()) + 'px',
     marginLeft: '-' + Math.round(scaleX * selection.x1) + 'px',
     marginTop: '-' + Math.round(scaleY * selection.y1) + 'px'
    });
   }
   function iasSubmit() {
    url = '/gravatars/crop-image/9918014efde7f467fda5c5775197f9c1/';
    url += "crop%5Bwidth%5D=" + grav.cropper.selection.width;
    url += "&crop%5Bheight%5D=" + grav.cropper.selection.height;
    url += "&crop%5Bx%5D=" + grav.cropper.selection.x1;
    url += "&crop%5By%5D=" + grav.cropper.selection.y1;
    url += "&crop%5Bscale%5D=1";
    window.location = url;
   }
   $(window).load(function () {
    ias = $('#cropimage').imgAreaSelect({
     aspectRatio: '1:1',
     x1: ( ( ($('#cropimage').width()/2) - 40 ) ),
     y1: ( ( ($('#cropimage').height()/2) - 40 ) ),
     x2: ( ( ($('#cropimage').width()/2) + 40 ) ),
     y2: ( ( ($('#cropimage').height()/2) + 40 ) ),
     onSelectChange: preview,
     borderWidth: 2
    });
    $(window).bind('resize', function() {
     ias = $('#cropimage').imgAreaSelect( ias.options );
    });
    preview($('#cropimage'), {
     width: 80,
     height: 80,
     x1: ( ( ($('#cropimage').width()/2) - 40 ) ),
     y1: ( ( ($('#cropimage').height()/2) - 40 ) )
    });
    $(document).ready(function() {
     var fadedelay = 650;

     $('#imgselectarea').css("opacity", 0);
     $('#imgselectarea').css("background", "yellow");
     $('#imgselectarea').fadeTo(fadedelay, 0.8, function() {
      $('#imgselectarea').fadeOut(fadedelay);
     });
    });
   });
</script>


类别:css&js | 添加到搜藏 | 浏览() | 评论 (1)
 
最近读者:
 
网友评论:
1
2008年11月14日 星期五 11:06 | 回复
不错。顶
 
发表评论:
姓 名:
网址或邮箱: (选填)
内 容:
验证码: 请点击后输入四位验证码,字母不区分大小写
      

     

©2009 Baidu