Skip to content

Instantly share code, notes, and snippets.

@loominade
Created April 1, 2015 08:02
Show Gist options
  • Save loominade/4082e9166739e8a25ab5 to your computer and use it in GitHub Desktop.
Save loominade/4082e9166739e8a25ab5 to your computer and use it in GitHub Desktop.
ever bothered there is a scrollLeft() but no scrollRight() function in jQuery?
$.fn.extend({
scrollRight: function(property) {
return this[0].scrollWidth - (this[0].scrollLeft + this[0].clientWidth) + 1;
}
});
@Slavezax
Copy link

You saved the day.

@RussellBishop
Copy link

Well that's extremely helpful. Thanks!

@rahul3n
Copy link

rahul3n commented Jun 21, 2018

@Eben-Hafkamp2
Copy link

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

@loominade
Copy link
Author

I just had the same problem and found this post from myself 5 years ago. Thanks me five years ago.

@avitalar
Copy link

avitalar commented Mar 3, 2020

lol loominade
Thank you indeed

@Duspy99
Copy link

Duspy99 commented Mar 26, 2020

Man ty!

@Tovape
Copy link

Tovape commented Sep 6, 2023

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