Created
April 1, 2015 08:02
-
-
Save loominade/4082e9166739e8a25ab5 to your computer and use it in GitHub Desktop.
ever bothered there is a scrollLeft() but no scrollRight() function in jQuery?
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
$.fn.extend({ | |
scrollRight: function(property) { | |
return this[0].scrollWidth - (this[0].scrollLeft + this[0].clientWidth) + 1; | |
} | |
}); |
pascal-hofmann
commented
May 12, 2016
•
You saved the day.
Well that's extremely helpful. Thanks!
And if you want to have it computed in a modern framework and you want to know if an element has been scrolled all the way over to the right (because otherwise you would just stick with scrollLeft
) just do something like this:
(this.$refs.track.scrollLeft + this.$refs.track.clientWidth) === this.$refs.track.scrollWidth
// Substitute "track" with whatever reference you created for your shadow element
I just had the same problem and found this post from myself 5 years ago. Thanks me five years ago.
lol loominade
Thank you indeed
Man ty!
this should be on the next version of ecma
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment