Created
July 6, 2017 18:58
-
-
Save glosik/2ed99bc9fee714f3775e4d7f5f95688d to your computer and use it in GitHub Desktop.
image-ratio angular
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
angular.module('malibuApp').directive('imageRatio', function () { | |
- return { | |
- restrict: 'A', | |
- link: function (scope, elem, attr) { | |
- elem.on('load', function () { | |
- var w = this.naturalWidth, | |
- h = this.naturalHeight; | |
- if (h > w) { | |
- $(this).addClass('portrait'); | |
- } else { | |
- $(this).addClass('landscape'); | |
- } | |
- }); | |
- } | |
- }; | |
-}); | |
<img image-ratio alt="{{::image.label}}" itemprop="thumbnail" ng-src="{{::image.uri}}" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment