Posted By

saturngod on 03/09/10


Tagged


Versions (?)

Move Center with Jquery


 / Published in: JavaScript
 

  1. $(document).ready(function() {
  2. jQuery.fn.centerScreen = function(loaded) {
  3. var obj = this;
  4. if(!loaded) {
  5. obj.css('top', $(window).height()/2-
  6. this.height()/2);
  7. obj.css('left', $(window).width()/2-
  8. this.width()/2);
  9. $(window).resize(function()
  10. { obj.centerScreen(!loaded); });
  11. } else {
  12. obj.stop();
  13. obj.animate({ top: $(window).height()/2-
  14. this.height()/2, left: $
  15. (window).width()/2-this.width()/2}, 200, 'linear');
  16. }
  17. }
  18. });

Report this snippet  

You need to login to post a comment.