X

LATEST #JQUERY NEWS

Using jQuery’s .resize() Method


jQuery’s .resize() method is a cool way to have an event triggered or have a function executed when something is resized. For the purposes of this tutorial, we’re going to show you how to use the .resize() method to trigger an alert method whenever the window is resized. You might be surprised at how easy this functionality is to add to any of your code.

In terms of syntax, the .resize() method is used in much the same was as any other jQuery method. Take a look at the snippet below to get a look for yourself:

$(window).resize(function(){
alert(“The window has been resized!”);
})

That’s all it takes to use the resize method to trigger an alert message once the window has been resized. Feel free to use the code and change the alert message to say whatever you like. Just be aware that if you are going to use this code, the alert messages that will appear will likely be very annoying for the user, as an alert will pop up whenever the window changes size, even if it happens in one fluid motion. Making the window 50px less wide will send 50 alert messages. Still, the concept behind the .resize() method is pretty neat, and a lot of different functionalities can be achieved by using it.

Recently Published

article image
»

Add Keyboard Shortcut to Anchor Tag Using jQuery

Making a user friendly website can be quite a challenging task. There ...

Screen Shot 2017-04-23 at 10.15.41 AM
»

How to Use jQuery to Create a Sticky Navigation on Scroll

Creating “sticky” elements is something that can often be ...

article image
»

How to Use jQuery’s Keystroke Methods

jQuery has a few built-in keystroke methods that are all triggered by ...

article image
»

How to Change iFrame Styling Using jQuery

If you’ve ever had the displeasure of working with iFrames, ...

article image
»

How to Use jQuery to Create Blinking Text

Blinking text is one of those cool features that you never actively ...

article image
»

Convert Images to Black and White using jQuery

Converting an image to black and white is no longer a manual event. ...

article image
»

How to Disable Right-Click Menu Using jQuery

There can be dozens of reasons why you may want to disable right ...

article image
»

How to Optimize jQuery Code for Better Performance

jQuery is the most popular client side library, in fact almost every ...

article image
»

Using Head.js to Load All Your JavaScript

In the past few years, client side frameworks/libraries have become ...