Skip to content

Instantly share code, notes, and snippets.

@glosik
Created July 6, 2017 18:58
Show Gist options
  • Save glosik/2ed99bc9fee714f3775e4d7f5f95688d to your computer and use it in GitHub Desktop.
Save glosik/2ed99bc9fee714f3775e4d7f5f95688d to your computer and use it in GitHub Desktop.
image-ratio angular
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