<script type="text/javascript" src="js/jquery-1.4.2.js"></script>
<script type="text/javascript">
$(document).ready(function() {
jQuery.fn.center = function() {
this.css("position", "absolute");
this.css("top", ($(window).height() - this.height()) / 2 + $(window).scrollTop() + "px");
this.css("left", ($(window).width() - this.width()) / 2 + $(window).scrollLeft() + "px");
return this;
}
$("#id").center();
});
</script>
//ID为要在屏幕上下左右居中的元素ID,而不是class
js实现使元素在屏幕里上下左右居中
最新推荐文章于 2025-02-27 19:40:51 发布