Skip to content

Instantly share code, notes, and snippets.

@kiub
Created July 22, 2015 18:22
Show Gist options
  • Save kiub/9b02370eb1443e1871a8 to your computer and use it in GitHub Desktop.
Save kiub/9b02370eb1443e1871a8 to your computer and use it in GitHub Desktop.
Add class to img if image is portrait or landscape
// 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