Multiple popups inside repeater

99封情书 提交于 2019-12-04 18:32:40

Instead of creating multiple popups to serve the same purpose, you can simply create one global popup and update its' content based on clicked listview item.

Give all listview items a class and attach an event listener on pagecrate of the page.

<li>
   <a href="#" class="thumb">
      <input type="image" src="img.jpg"/>
   </a>
</li>

Create a popup inside page div.

<div id="myPopup" data-role="popup" data-overlay-theme="b" data-transition="fade" data-shadow="false" data-theme="a">
</div>

Once a listview item received an event, retrieve popup, listview item and image src. Insert the retrieved image into the popup and then open it once image is loaded to ensure that the popup is positioned to the listview item.

$(document).on("pagecreate", "#pageID", function () {
    /* attach event listener */
    $(".thumb").on("click", function (e) {
        /* retrieve data */
        var popup = $("#myPopup"),
            elm = $(this),
            img = $("input", elm).attr("src");
        /* insert img into popup and the open it */
        popup.html($("<img/>", {
            src: img
        }).one("load", function (e) {
            popup.popup("open", {
                positionTo: elm
            });
        }));

    });
});

Demo

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