我一直在编写代码来使用jQueryimgAreaSelect
插件标记图像。为此,我有一个在单击图像时弹出的模态,并且模态包含内容以标记图像。这部分工作正常。我面临的问题是当我关闭模态时,即使在模态关闭后,我在图像上绘制的边界框仍然存在。我想删除那个模态背景,但我不知道如何继续。
我在 https://jsfiddle.net/Uviii/rb67myvn/2/下面附上了 Jsfiddle 的链接
html:
<div id="myModal" class="modal">
<!-- The Close Button -->
<span class="close">×</span>
<!-- Modal Content (The Image) -->
<div id="imagearea" class="imagearea">
<div class='dynamic_text' style='display:none;'></div>
<img class="modal-content" id="img01" src="fashion.jpg">
</div>
<div class="text_container">
<br>
<div class="img_text"></div>
<div class="input_tag">
<span class="right_sec_text">Select a region from the picture</span>
<div class="error"></div>
<div class="tags"></div>
<div class="input_box">
<input type="text" name="tags" class="input_textbox">
<button id="settag" class="btn_settag">Set Tag</button>
</div>
<input type="hidden" name="x1" id="x1" value="-">
<input type="hidden" name="y1" id="y1" value="-">
<input type="hidden" name="x2" id="x2" value="-">
<input type="hidden" name="y2" id="y2" value="-">
<input type="hidden" name="w" id="w" value="-">
<input type="hidden" name="h" id="h" value="-">
<div class="footer_btn">
<p><button class="btn_success">Confirm Selection</button>
<p><button class="btn_cancel" onclick="$('#myModal').hide()">Cancel</button>
</div>
</div>
</div>
</div>
脚本:
function preview(img, selection) {
if (!selection.width || !selection.height)
return;
$('#x1').val(selection.x1);
$('#y1').val(selection.y1);
$('#x2').val(selection.x2);
$('#y2').val(selection.y2);
$('#w').val(selection.width);
$('#h').val(selection.height);
$('.img_error').removeClass("error");
}
$(function() {
$('#img01').imgAreaSelect({
handles: true,
fadeSpeed: 200,
onSelectChange: preview
});
});
var modal = document.getElementById("myModal");
// Get the image and insert it inside the modal - use its "alt" text as a caption
var img = document.getElementById("imgside");
var modalImg = document.getElementById("img01");
img.onclick =function(){
modal.style.display = "block";
modalImg.src = this.src;
}
// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];
// When the user clicks on <span> (x), close the modal
span.onclick = function() {
modal.style.display = "none";
}
下面的第一张图片是带有图像和边界框的模态:
下图显示模态关闭且边界框的灰度保持不变
有人可以帮我解决这个问题吗?