【jQuery】要素を中央に配置する関数


jQuery.fn.center = function () {
	this.css("position","absolute");
	this.css("top", Math.max(0, (($(window).height() - $(this).outerHeight()) / 2) + $(window).scrollTop()) + "px");
	this.css("left", Math.max(0, (($(window).width() - $(this).outerWidth()) / 2) + $(window).scrollLeft()) + "px");
	return this;
}

// 使用
$( "#id" ).center();

出典元 Using jQuery to center a DIV on the screen


レシピブック(レシピ登録アプリ)
手書きノート(メモ登録アプリ)

投稿日

カテゴリー:

ブログランキング・にほんブログ村へ

コメント

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です