Jquery jcrop不裁剪预览窗口中的内容

Jquery jcrop不裁剪预览窗口中的内容,jquery,jcrop,Jquery,Jcrop,我们正在使用jcrop为用户帐户裁剪图像。我们正在使用以下jcrop设置。我们得到的最终裁剪图像稍微放大。我们正在使用纵横比1.0和boxSize属性 <script type="text/javascript"> jQuery(function ($) { // Create variables (in this scope) to hold the API and image size var jcrop_api, boundx,

我们正在使用jcrop为用户帐户裁剪图像。我们正在使用以下jcrop设置。我们得到的最终裁剪图像稍微放大。我们正在使用纵横比1.0和boxSize属性

<script type="text/javascript">
jQuery(function ($) {

    // Create variables (in this scope) to hold the API and image size
    var jcrop_api,
        boundx,
        boundy,

        // Grab some information about the preview pane
        $preview = $('#preview-pane'),
        $pcnt = $('#preview-pane .preview-container'),
        $pimg = $('#preview-pane .preview-container img'),

        xsize = $pcnt.width(),
        ysize = $pcnt.height();

    $('#target').Jcrop({
        onChange: updatePreview,
        onSelect: updatePreview,
        bgColor: 'white',
        bgOpacity: .4,
        addClass: 'jcrop-light',
        boxWidth: 450,
        boxHeight: 400,
        aspectRatio: 1
    }, function () {
        // Use the API to get the real image size
        var bounds = this.getBounds();
        boundx = bounds[0];
        boundy = bounds[1];
        // Store the API in the jcrop_api variable
        jcrop_api = this;
        jcrop_api.setSelect([0, 0, 200, 200]);
        jcrop_api.setOptions({
            bgFade: true
        });
        jcrop_api.ui.selection.addClass('jcrop-selection');

        // Move the preview into the jcrop container for css positioning
        $preview.appendTo(jcrop_api.ui.holder);
    });

    function updatePreview(c) {
        $('#x').val(c.x);
        $('#y').val(c.y);
        $('#w').val(c.w);
        $('#h').val(c.h);
        $('#x2').val(c.x2);
        $('#y2').val(c.y2);
        var rx = 200 / c.w; // 200 - preview box size
        var ry = 200 / c.h;
        if (parseInt(c.w) > 0) {
            var rx = xsize / c.w;
            var ry = ysize / c.h;

            $pimg.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'
            });
        }
    };
});
</script>

jQuery(函数($){
//创建变量(在此范围内)以保存API和图像大小
var jcrop_api,
庞德,
庞迪,
//获取有关预览窗格的一些信息
$preview=$(“#预览窗格”),
$pcnt=$(“#预览窗格.预览容器”),
$pimg=$(“#预览窗格.预览容器img”),
xsize=$pcnt.width(),
ysize=$pcnt.height();
$('#target').Jcrop({
onChange:updatePreview,
onSelect:updatePreview,
bgColor:'白色',
不透明度:.4,
addClass:'jcrop light',
箱宽:450,
箱高:400,
方面:1
},函数(){
//使用API获得真实的图像大小
var bounds=this.getBounds();
boundx=边界[0];
boundy=边界[1];
//将API存储在jcrop_API变量中
jcrop_api=这个;
jcrop_api.setSelect([0,0200200]);
jcrop_api.setOptions({
是的
});
jcrop_api.ui.selection.addClass('jcrop-selection');
//将预览移动到jcrop容器中以进行css定位
$preview.appendTo(jcrop_api.ui.holder);
});
函数updatePreview(c){
$('#x').val(c.x);
$('y').val(c.y);
$('w').val(c.w);
$('h').val(c.h);
$('x2').val(c.x2);
$('y2').val(c.y2);
var rx=200/c.w;//200-预览框大小
var ry=200/c.h;
如果(parseInt(c.w)>0){
var rx=xsize/c.w;
var ry=ysize/c.h;
$pimg.css({
宽度:数学圆(rx*boundx)+“px”,
高度:数学圆(ry*boundy)+“px”,
marginLeft:“-”+数学四舍五入(rx*c.x)+“px”,
marginTop:“-”+数学圆(ry*c.y)+“px”
});
}
};
});

如果您正在裁剪头像/个人资料图像,我强烈建议您使用

这是一个非常轻量级的插件,允许裁剪、缩放和旋转图像,它具有触摸支持和响应能力(流体)。它非常适合裁剪个人资料图片()

我希望这是你所需要的,并帮助你解决这个问题