Created
March 19, 2015 03:35
-
-
Save okuden-labo/f0e11d2100599ca83a23 to your computer and use it in GitHub Desktop.
jQueryで画面の中心
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 画面の中心に要素を配置 */ | |
$(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; | |
} | |
$("#my-id").center(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment