我使用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你試過了嗎? –