Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

x-, y-positions of viewport's right, bottom edges (respectively)?

I'm looking for a plugin-free way to get the x-coordinate of the visible viewport's right edge, and likewise, the y-coordinate of its bottom edge, using either jQuery or "plain" JavaScript.

Thanks!

like image 732
kjo Avatar asked Dec 27 '22 13:12

kjo


2 Answers

var width = document.documentElement.clientWidth || window.innerWidth;
var height= document.documentElement.clientHeight|| window.innerHeight;
like image 70
Niet the Dark Absol Avatar answered Jan 14 '23 13:01

Niet the Dark Absol


I finally settled for this (jQuery-based) solution:

var $w = $(window);
var right_edge_x  = $w.scrollLeft() + $w.width();
var bottom_edge_y = $w.scrollTop()  + $w.height();

I'm not sure exactly how it differs from the other solutions proposed, let alone whether it's better, but at least I can make some sense of it...

like image 29
kjo Avatar answered Jan 14 '23 13:01

kjo