hellomello
hellomello

Reputation: 8587

jquery : dynamically alert while user changes size of browser

If a user resizes a browser I want to display an alert. What I'm trying to do is change the users image width/height with jQuery. When the user resizes the browser, the image will be resized dynamically. So if someone can show me how to do it with alert, I think I can try to figure out the rest.

Right now I know how to get the user's current browser height and width, but it will only alert on load.

$(document).ready(function(){
    var docWidth = $(document).width();
    alert(docWidth);
});

So this will give user's docWidth when browser opens.

Also, if someone has time to explain the difference between window and document width's and height. I tried both scenarios and its giving me the same information.

Thanks for the help!

Upvotes: 1

Views: 567

Answers (1)

lonesomeday
lonesomeday

Reputation: 237865

Use the window's resize event:

$(window).resize(function() {
    //run code on window resize
});

See the API reference

Upvotes: 2

Related Questions