js取得置中位置
- 左右皆置中
var $dialog = $("<div>hello</div>");
var left = ($(window).width() - $dialog.outerWidth()) / 2 + $(window).scrollLeft() + "px";
var top = ($(window).height() - $dialog.outerHeight() ) / 2 + $(window).scrollTop() + "px";
- click button後,置於button正下方
onclick = "showDialog(this)
function showDialog(obj)
var margin_top = 30; //自行預設設margin top距離
var pos = $(obj).offset();
var eWidth = $(obj).outerWidth();
var mWidth = $confirmBox.outerWidth();
var left = (pos.left - mWidth/2) + "px";
var top = margin_top + pos.top + "px";
沒有留言:
張貼留言