當我點擊鏈接在第一時間,在彈出的不居中,但第二次是。我跟着answers的其他問題說,使用'positionTo': 'window'
,但問題發生在我是否擁有它。還有其他解決方案表示使用超時,但我不想使用它。jQuery Mobile的:用動態加載的圖像彈出未居中首先點擊
function setImage()
{
$('#image-popup img').attr('src', 'https://upload.wikimedia.org/wikipedia/commons/7/7b/Orange-Whole-%26-Split.jpg');
$('#image-popup img').on('load', function() {
console.log('loaded image from click');
$('#image-popup').popup('reposition', {'positionTo': 'window'});
});
}
<html>
<head>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css" />
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
</head>
<body>
<a href='#image-popup' data-rel="popup" data-position-to="window" onclick='setImage()'>Open image</a>
<div id='image-popup' data-role='popup'>
<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 class="popphoto" src="" alt="orange">
</div>
</body>
</html>
請注意,你需要,如果你運行多次清空緩存並硬性重新加載。
http://stackoverflow.com/a/26587363/1771795 – Omar