Jquery CSS:显示裁剪图像的预览
我正在使用Jcrop裁剪图像,并获得坐标。我想在单击“预览”按钮时显示裁剪零件的预览。我不知道如何才能做到这一点。您可以在使用ajax单击预览按钮并将其加载到模式或fancybox后裁剪并保存图像。您可以在使用ajax单击预览按钮并将其加载到模式或fancybox后裁剪并保存图像偏差Jquery CSS:显示裁剪图像的预览,jquery,html,css,jcrop,Jquery,Html,Css,Jcrop,我正在使用Jcrop裁剪图像,并获得坐标。我想在单击“预览”按钮时显示裁剪零件的预览。我不知道如何才能做到这一点。您可以在使用ajax单击预览按钮并将其加载到模式或fancybox后裁剪并保存图像。您可以在使用ajax单击预览按钮并将其加载到模式或fancybox后裁剪并保存图像偏差 $(function () { var $target = $('#target'), $preview = $('#preview'); // hold the coordinat
$(function () {
var $target = $('#target'),
$preview = $('#preview');
// hold the coordinates of the cropped image
var coords;
// initialize the widget
$target.Jcrop({
// save the coordinates of the cropped image after selecting
onSelect: function (c) {
coords = c;
}
});
// when a button is clicked, show preview of the cropped image using the saved coordinates
$('button').on('click', function () {
// make a copy of the image with the original dimensions
var $img = $('<img/>', {
src: $target[0].src,
css: {
position: 'absolute',
left: '-' + Math.round(coords.x) + 'px',
top: '-' + Math.round(coords.y) + 'px',
width: $target.css('width'),
height: $target.css('height')
}
});
// set the dimensions of the preview container
$preview.css({
position: 'relative',
overflow: 'hidden',
width: Math.round(coords.w) + 'px',
height: Math.round(coords.h) + 'px'
});
// add+position image relative to its container
$preview.html($img);
});
});
$(函数(){
var$target=$(“#target”),
$preview=$(“#preview”);
//保留裁剪图像的坐标
var-coords;
//初始化小部件
$target.Jcrop({
//选择后保存裁剪图像的坐标
onSelect:函数(c){
coords=c;
}
});
//单击按钮时,使用保存的坐标显示裁剪图像的预览
$('button')。在('click',函数(){
//复制具有原始尺寸的图像
变量$img=$('
这里有一个。这里有一种方法可以按照他们的方法进行操作,但有一些偏差
$(function () {
var $target = $('#target'),
$preview = $('#preview');
// hold the coordinates of the cropped image
var coords;
// initialize the widget
$target.Jcrop({
// save the coordinates of the cropped image after selecting
onSelect: function (c) {
coords = c;
}
});
// when a button is clicked, show preview of the cropped image using the saved coordinates
$('button').on('click', function () {
// make a copy of the image with the original dimensions
var $img = $('<img/>', {
src: $target[0].src,
css: {
position: 'absolute',
left: '-' + Math.round(coords.x) + 'px',
top: '-' + Math.round(coords.y) + 'px',
width: $target.css('width'),
height: $target.css('height')
}
});
// set the dimensions of the preview container
$preview.css({
position: 'relative',
overflow: 'hidden',
width: Math.round(coords.w) + 'px',
height: Math.round(coords.h) + 'px'
});
// add+position image relative to its container
$preview.html($img);
});
});
$(函数(){
var$target=$(“#target”),
$preview=$(“#preview”);
//保留裁剪图像的坐标
var-coords;
//初始化小部件
$target.Jcrop({
//选择后保存裁剪图像的坐标
onSelect:函数(c){
coords=c;
}
});
//单击按钮时,使用保存的坐标显示裁剪图像的预览
$('button')。在('click',函数(){
//复制具有原始尺寸的图像
变量$img=$('
这里有一个。在我的情况下,除非预览图像得到用户的批准,否则我不想保存图像。有什么办法吗?在我的情况下,除非预览图像得到用户的批准,否则我不想保存图像。有什么办法吗?你尝试过任何代码吗?你尝试过任何代码吗?非常感谢。你救了我一天。这正是我想要的。不是非常感谢你。你救了我一天。这正是我想要的。