Modify the “options” parameter of popupbeforeposition event

℡╲_俬逩灬. 提交于 2019-12-01 08:03:18

问题


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.


回答1:


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

Demo




回答2:


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"
            });
        }
    });
});


来源:https://stackoverflow.com/questions/19630799/modify-the-options-parameter-of-popupbeforeposition-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!