JSFiddle - React, Tailwind, and code Playground
by vijayweb
HTML
<!-- JavaScript -->
<p>
<strong>JavaScript resize:</strong>
<span id="jsWidth">0</span>,
<span id="jsHeight">0</span>
</p>
<br/>
<!-- jQuery -->
<p>
<strong>jQuery resize:</strong>
<span id="jqWidth">0</span>,
<span id="jqHeight">0</span>
</p>
JavaScript
// JavaScript
function jsUpdateSize(){
// Get the dimensions of the viewport
var width = window.innerWidth ||
document.documentElement.clientWidth ||
document.body.clientWidth;
var height = window.innerHeight ||
document.documentElement.clientHeight ||
document.body.clientHeight;
document.getElementById('jsWidth').innerHTML = width;
document.getElementById('jsHeight').innerHTML = height;
};
window.onload = jsUpdateSize; // When the page first loads
window.onresize = jsUpdateSize; // When the browser changes size
// jQuery
function jqUpdateSize(){
// Get the dimensions of the viewport
var width = $(window).width();
var height = $(window).height();
$('#jqWidth').html(width);
$('#jqHeight').html(height);
};
$(document).ready(jqUpdateSize); // When the page first loads
$(window).resize(jqUpdateSize); // When the browser changes size