jQuery图片截图工具(默认为图片宽度)

最近给编辑做了个截图工具

一、功能:

    A:图片自动载入

    B:图片载入时,截取工具大小为图片大小

    C:所截取图片长宽比例2.5:1

二、引用插件:jquery.Jcrop.js

三、代码

  <head>
    <meta http-equiv="Content-type" content="text/html;charset=UTF-8" /> 
    <title>图片处理工具</title>
    <script src="js/jquery.min.js" type="text/javascript"></script>
    <script src="js/jquery.Jcrop.js" type="text/javascript"></script>
    <script type="text/javascript" src="js/jquery.imgareaselect-width.js"></script>
    <link rel="stylesheet" href="css/jquery.Jcrop.css" type="text/css" />
    <link rel="stylesheet" href="css/demos.css" type="text/css" />
    <script type="text/javascript">
        jQuery(function($){
        var jcrop_api, boundx, boundy;
        imgReady('img/1.jpg', function (){
            $('#target').Jcrop({
            onChange: updatePreview,
            onSelect: updatePreview,
            onRelease:  clearCoords,
            aspectRatio: 2.5,
            setSelect: [ 0, 0, this.width, this.height/2.5 ]
            },function(){
                var bounds = this.getBounds();
                boundx = bounds[0];
                boundy = bounds[1];
                jcrop_api = this;
            });
        });
        function updatePreview(c){
            $('#x1').val(c.x);
            $('#y1').val(c.y);
            $('#x2').val(c.x2);
            $('#y2').val(c.y2);
            $('#w').val(c.w);
            $('#h').val(c.h);
            if (parseInt(c.w) > 0){
                var rx = 400 / c.w;
                var ry = 160 / c.h;
                $('#preview').css({
                    width: Math.round(rx * boundx) + 'px',
                    height: Math.round(ry * boundy) + 'px',
                    marginLeft: '-' + Math.round(rx * c.x) + 'px',
                    marginTop: '-' + Math.round(ry * c.y) + 'px'
                });
            }
        };
    });
    function clearCoords(){
      $('#coords input').val('');
    };
    </script>
  </head>



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值