Reputation: 530
I am using the Popup widget of the jQuery Mobile library (version 1.3.1). I am trying to handle some code in the beforeposition
event. The documentation says that:
Handling this event gives an opportunity to modify the content of the popup before it appears on the screen. For example, the content can be scaled or parts of it can be hidden or removed if it is too wide or too tall. You can also modify the options parameter to affect the popup's placement. The properties inside the options object available for modification are the same as those used by the reposition method.
I need to set the x
and y
parameters but I could not figure out how to modify the options parameter of the event. A code example would be awesome. Thanks for your time.
Upvotes: 2
Views: 3827
Reputation: 31732
beforeposition
events omits an object containing values of popup's position (options), x
, y
and positionTo
.
To modify those options once beforeposition
triggers, use the below.
$( ".selector" ).on( "popupbeforeposition" , function (e, ui) {
ui.x = value;
ui.y = value;
/* OR
ui.positionTo = "window"
*/
});
If you wish to open a popup programmatically, use the below.
$( ".selector" ).popup( "open", {
x: value,
y: value
});
value = number in pixels
Upvotes: 4
Reputation: 24738
Here is a jsFiddle Demo: http://jsfiddle.net/ezanker/3pW3P/
I used the popupafteropen event instead and used the reposition method:
$("#page1").on("pageinit", function () {
$("#popupPadded").on({
popupafteropen: function () {
$(this).popup("reposition", {
x: 70,
y: 115,
positionTo: "window"
});
}
});
});
Upvotes: 1