Advertisement
arkader

Absolute center an image [JS works sometimes]

Apr 13th, 2013
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function(){
  2.  
  3.     var partenaires = {
  4.  
  5.         init: function() {
  6.             this.centerImg();
  7.         },
  8.  
  9.         centerImg: function() {
  10.  
  11.             $('.partenaires').find('img').each(function() {
  12.                 console.log(this);
  13.                 //On récup la dimension de l'image
  14.                 var $this = $(this),
  15.                 widthImg = $this.width(),
  16.                 heightImg = $this.height();
  17.  
  18.                 //On centre l'image
  19.                 $this.css({
  20.                     'top':'80px',
  21.                     'left': '160px',
  22.                     'margin-left':-widthImg/2,
  23.                     'margin-top': -heightImg/2
  24.                 });
  25.  
  26.             });
  27.         }// centerImg()
  28.     };
  29.  
  30.     partenaires.init();
  31.  
  32. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement