【发布时间】:2018-05-01 07:29:57
【问题描述】:
我正在使用 Jcrop 插件来裁剪带有预览缩略图的图片。 Jcrop 插件使用内部 jcrop-active div 创建预览图像。那么如何在其他 div 中更改预览 div 层呢?
https://jsfiddle.net/cuwfpo45/ 上的工作示例
这里是 HTML:
<div id="form-photo" class="form-photo clearfix">
<div class="form-group">
<img src="<?php echo $image; ?>" id="target" />
</div>
<form id="" class="s-form" method="POST" action="test3.php" onsubmit="return checkCoords();">
<input type="hidden" id="x" name="x" />
<input type="hidden" id="y" name="y" />
<input type="hidden" id="w" name="w" />
<input type="hidden" id="h" name="h" />
<input type="hidden" name="image" value="<?php echo $image; ?>" />
<input type="submit" value="Submit" />
</form>
这是我的 JS 代码:
$(function(){
var box_width = $('#form-photo').width();
$('#target').Jcrop({
setSelect: [ 100, 100, 500, 500 ],
aspectRatio: 1,
onSelect: updateCoords,
onChange: updateCoords,
boxWidth: box_width
},function(){
var jcrop_api = this;
thumbnail = this.initComponent('Thumbnailer', { width: 330, height: 320 });
});
});
function updateCoords(c)
{
$('#x').val(c.x);
$('#y').val(c.y);
$('#w').val(c.w);
$('#h').val(c.h);
};
function checkCoords()
{
if (parseInt($('#w').val())) return true;
alert('Please select a crop region then press submit.');
return false;
};
感谢您的帮助!
【问题讨论】:
-
请也分享您的 HTML 设置。
-
请看帖子,用HTML编辑,谢谢!
-
所以你想在另一个潜水而不是默认的潜水中显示这个预览?让我编辑我的答案
-
是的,正确,我想将父 div 更改为另一个而不是默认值。
-
我进行了必要的调整以在指定的图像元素中显示预览,而不是默认的。请检查并告诉我是否可以。