Wicket ModalWindow position

2019-05-29 10:29发布

问题:

I need to modify the position of the modal window before it gets displayed in the middle.

I have a ajaxbutton which will open the modal window. In the onClick method I tried something like...

target.appendJavaScript("$(\".wicket-modal\").css('width', 888+'px');");

or

target.appendJavaScript("$(\"[id^=_wicket_window]\").css('top', 100+'px');");

and some more variations of it...

It seems I can't manipulate the position of the ModalWindow before it gets displayed. But I can manipulate the position and size of an element INSIDE this modal window.

For example:

target.appendJavaScript("$(\".formdiv\").css('width', 888+'px');");

works. "formdiv" is a div in the modal window. It changes it's width, color and what I want.

But I need the position of the ModalWindow somewhere else at the first appearance. How can I do it?

回答1:

For an unknown reason to me the ModalWindow is opened with JavaScript timeout of 0 seconds. So you need to execute your custom JavaScript again with a timeout, e.g.:

target.appendJavaScript("setTimeout(function() {$('.wicket-modal').css('width', 888+'px');}, 10);");