我使用Jcrop裁剪图像,我正在获取坐标。我想在点击“预览”按钮后显示裁剪部分的预览。我不知道我该怎么做到这一点。CSS:裁剪图像的显示预览
0
A
回答
2
这里做以下的thumbnail example有一些偏差的一种方式。
$(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);
});
});
这里有一个demo。
+0
非常感谢。你拯救了我的一天。这正是我想要的。 – Sambit
0
相关问题
- 1. CSS - 裁剪图像显示
- 2. Android的预览图像裁剪
- 3. 显示裁剪图像
- 4. 显示图像裁剪
- 5. 裁剪/剪切相机预览只显示图像的上半部分
- 6. 裁剪AVCaptureSession预览
- 7. 使用css裁剪图像
- 8. 在CSS中裁剪图像
- 9. 在ImageView上显示剪裁的图像
- 10. 在UIImageView中显示前裁剪图像
- 11. 图像裁剪显示黑色bg
- 12. 使用android camera2在相机预览和裁剪图像中显示矩形2
- 13. JQuery上传,预览,剪裁
- 14. CSS显示图像调整大小和裁剪 - 继续
- 15. 裁剪图像
- 16. 裁剪图像
- 17. 裁剪图像
- 18. 预览屏幕中的钛中裁剪图像
- 19. WinRT中的裁剪/裁剪图像
- 20. 图像预览未显示
- 21. 以CSS的百分比裁剪图像
- 22. 从底部裁剪图像的CSS
- 23. JCrop不按预期裁剪图像
- 24. Laravel多重上传与图像预览然后裁剪
- 25. 在上传之前预览图像并将其裁剪
- 26. 如何在拍摄照片后在预览中裁剪图像?
- 27. 使用jcrop裁剪后不会缩短预览图像
- 28. jQuery裁剪图像并观看实时预览
- 29. 使用jcrop使用预览裁剪图像
- 30. 无法剪裁/裁剪图像
anycode你试过了吗? –