Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium



Posted on 2013-12-03
Medium Priority
Last Modified: 2013-12-03
Is there a way to run a script when the window width changes only and not when the window height changes?
At the moment I am using $(window).resize(functionname) but this obviously fires when the window size changes vertically or horizontally.

Question by:Al4ddin2
LVL 44

Accepted Solution

Rainer Jeschor earned 2000 total points
ID: 39692522
there is no specific event for width change - you still have to use the resize event and then check the original and new width like:
var orgwidth = $(window).width();
   if($(this).width() != orgwidth ){
      // Update the window check width
      orgwidth = $(this).width();
       // Anything you want to do when the width changes

Open in new window


Author Comment

ID: 39692574
perfect, thanks.

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

569 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question