Solved

window.resize()

Posted on 2013-12-03
2
152 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 44

Accepted Solution

by:
Rainer Jeschor earned 500 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
Suggested Courses
Course of the Month11 days, 16 hours left to enroll

623 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