How can I possibly figure out the distance from an object (div) to the right browser window border?
http://www.screencast.com/t/ryNgwa4E
Thanks!
How can I possibly figure out the distance from an object (div) to the right browser window border?
http://www.screencast.com/t/ryNgwa4E
Thanks!
$(window).width() - ($('#your-element').offset().left + $('#your-element').width());
That takes the width of your element adds it to the position of the element within the document and takes it away from the whole window size which should leave you with the right hand distance between element and window.
If you need to include element's border, replace .width()
for .outerWidth()
:
el = $('#your-element');
$(window).width() - (el.offset().left + el.outerWidth());
Without jQuery:
elRect = document.getElementById('your-element').getBoundingClientRect();
window.innerWidth - elRect.right
For browser compatibility refer to getBoundingClientRect (IE9+)