Created
July 22, 2015 18:22
-
-
Save kiub/9b02370eb1443e1871a8 to your computer and use it in GitHub Desktop.
Add class to img if image is portrait or landscape
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
// html: <img ng-src="image-url.jpg" class="horizontal" orientable /> | |
app.directive('orientable', function () { | |
return { | |
link: function(scope, element, attrs) { | |
element.bind("load" , function(e){ | |
// success, "onload" catched | |
// now we can do specific stuff: | |
if(this.naturalHeight > this.naturalWidth){ | |
this.className = "vertical"; | |
} | |
}); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment