I have a div with id popupBasic for popup in Jquery Mobile
<div data-role="popup" id="popupBasic">
<a href="#" data-rel="back" class="ui-btn ui-corner-all ui-shadow ui-btn-a ui-icon-delete ui-btn-icon-notext ui-btn-right">Close</a><img id="imgView" />
</div>
In order to Open the popup on a button click btnViewPopup following code is used.
function btnViewPopup() {
try {
if (localStorage.imageURL == undefined || localStorage.imageURL.length == 0 || localStorage.imageURL == "undefined") {
Notify(22);
}
else {
var source = localStorage.imageURL
$("#imgView").attr('src', source);
$("#popupBasic").popup("open");
}
}
catch (err) {
ErrorMessageDB("Issue Attachments", "btnAttViewClick", "", "click-to view attachment", err.message, localStorage.EmployeesKId4LastModifiedBy);
}
}
Current implementation
- there is a radiobutton list for list of images.
- if select one its image URL will be stored in local storage.
- When click View Button, set src of the imgView with the value in localstorage
- Call Popup("Open")
My problem is first time when i click View button,image displayed is small and it is aligned to middle right. next time when i open another or same image it is displaying full as i expected. i did not given height and width for image, as it may be different for different images.
what am i doing wrong?
Thanks in advance
Your popup is being shown before knowing the image dimensions. You can open the popup after the image is loaded, as follows:
CSS:
JS:
Here is the DEMO.