Sometimes you need place image at center of div tag. The script below will help you calculate the size of image and change margin-top to set image into right position.
It is AngularJS and CoffeeScript
1 2 3 4 5 6 7 |
app.directive 'eventImage', ()-> restrict: 'ACE', link: ($scope, element, attrs, ctrl) -> # check image loaded element.bind 'load', -> if (element[0].width > element[0].height) element[0].style.marginTop = (element[0].width - element[0].height)/2 + 'px' |