问题
I have a popup in jquery mobile
<div data-role="popup" id="itemDetails">
...
</div>
and I call programmatically to open with:
$('#itemDetails').popup('open');
, but always open centered in x,y
on screen, and I want show fix to top (y=0)
of screen, and fixed when I have scroll.
How I can do it?, Thanks in advance.
回答1:
Something like CSS should be enough:
#itemDetails{
position:fixed;
top:0px;
}
If you really want to use jQuery, then
$('#itemDetails').css({position:'fixed',top:'0'});
回答2:
The solution did not work for me. Putting the css in the .css file did not take effect. I found that I needed to use the second type with:
$("#popupBasic").popup('open');
$('#popupBasic').css({position:'fixed',top:'10px',left:'30px','display':'block'});
then to close the popup:
$('#popupBasic').popup('close');
$('#popupBasic').css({display:'none'});
来源:https://stackoverflow.com/questions/15130420/how-to-position-popup-at-top-of-screen-or-fixed-at-top-in-jquery-mobile