I am trying to learn some JQuery, mainly for fun, but also for seriouz.
This is a tiny program, it displays the width of the window upon load of the document.
function window_width(window_w){
var window_w = ($(window).width());
var canvas = document.getElementById("width_w");
if (canvas.getContext) {
var ctx = canvas.getContext("2d");
ctx.strokeText(window_w, 0, 10);
ctx.stroke();
}
}
What I want it to do further is to keep updating the display of this variable as someone would re-size the window. I am not sure how to do this, do I need to write another function or is there a method for it?
You can bind a function to the resize event with jQuery: