[英]jquery imgAreaSelect not working in bootstrap modal window
I am playing with jQuery imgareaselect plugin located here: https://plugins.jquery.com/imgareaselect/ 我正在玩位于此处的jQuery imgareaselect插件: https ://plugins.jquery.com/imgareaselect/
and works like so: 像这样工作:
$('#img_for_select').imgAreaSelect({
x1: 10,
y1: 10,
x2: 100,
y2: 100,
handles: true,
parent: '#modal_content'
});
here's a fiddle for pure imgAreaSelect to demonstrate that it does work http://jsfiddle.net/kurtgn/vaf5f9mf/ 这是纯imgAreaSelect的小提琴,以证明它确实有效http://jsfiddle.net/kurtgn/vaf5f9mf/
and here's one that triggers a modal window and tries to apply the same imgAreaSelect to the same image (inside the modal). 这是一个触发模式窗口并尝试将相同imgAreaSelect应用于相同图像(模式内部)的窗口。 http://jsfiddle.net/kurtgn/f0x8o2L7/ http://jsfiddle.net/kurtgn/f0x8o2L7/
why doesn't the latter work? 后者为什么不起作用?
You can use imgAreaSelect right after the modal is opened by using its shown.bs.modal
event. 您可以在模态打开后立即使用imgAreaSelect来使用它的shown.bs.modal
事件。 Like this 像这样
var myModal = $('#myModal').modal({
show: false
});
myModal.on('shown.bs.modal', function () {
$('#img_for_select').imgAreaSelect({
x1: 10,
y1: 10,
x2: 100,
y2: 100,
handles: true,
parent: '.modal-content'
});
});
Also, the parent should be .modal-content
and not #modal-content
. 另外,父对象应为.modal-content
而不是#modal-content
。 (That's not the issue though) (但这不是问题)
Here is a demo http://jsfiddle.net/dhirajbodicherla/f0x8o2L7/7/ 这是一个演示http://jsfiddle.net/dhirajbodicherla/f0x8o2L7/7/
PS: PS:
Made the below changes to the button so that the modal window is opened on click 对按钮进行以下更改,以便在单击时打开模式窗口
<button type="button" data-toggle="modal" href="#myModal" class="btn btn-primary btn-lg" id="modalWindow">Launch demo modal</button>
Remove this line and it will work: 删除此行,它将起作用:
parent: '#modal_content'
Your code should now look like : 您的代码现在应如下所示:
$('#modalWindow').click(function(){
$('#myModal').modal();
$('#img_for_select').imgAreaSelect({
x1: 10, y1: 10, x2: 100, y2: 100,
handles: true
});
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.