-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathviewport.js
31 lines (30 loc) · 1.07 KB
/
viewport.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*
// jquery plugin under the WTF licence
// created by @waxzce after reading this article : http://andylangton.co.uk/articles/javascript/get-viewport-size-javascript/
// have fun
*/
(function($) {
$.fn.getViewport = function(){
var viewportwidth;
var viewportheight;
if (typeof window.innerWidth != 'undefined')
{
viewportwidth = window.innerWidth,
viewportheight = window.innerHeight
}
else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0)
{
viewportwidth = document.documentElement.clientWidth,
viewportheight = document.documentElement.clientHeight
}
else
{
viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
viewportheight = document.getElementsByTagName('body')[0].clientHeight
}
return {
width: viewportwidth,
height: viewportheight
};
};
})(jQuery);