Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

window.resize()

Posted on 2013-12-03
2
Medium Priority
?
169 Views
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.

Thanks
0
Comment
Question by:Al4ddin2
2 Comments
 
LVL 44

Accepted Solution

by:
Rainer Jeschor earned 2000 total points
ID: 39692522
Hi,
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();
$(window).resize(function(){
   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


HTH
Rainer
0
 

Author Comment

by:Al4ddin2
ID: 39692574
perfect, thanks.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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

916 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