2

I already looked for the .resize() jquery function but the jquery .resize() only triggers when the window is being resized, what i wanted was a trigger that shoots when the width changes for example, instead of changing the browser width the user clicks in the button to maximize and the function fails to trigger, i have a function that fires a function on resize(), is there any function that is like on("windowwidthchanges") ?

1
  • Is your button click throwing an error? Commented Jun 1, 2016 at 17:58

3 Answers 3

3

You can detect both events and just execute code when it's a width change:

var width = $(window).width();
$(window).resize(function(){
   if($(this).width() != width){
      width = $(this).width();
       console.log(width);
   }
});
Sign up to request clarification or add additional context in comments.

Comments

0

I've checked Chrome, Firefox and IE11. All 3 browsers trigger the alert when the maximize button is clicked.

$(window).resize(function(){ alert("resized"); });

What, specifically, are you trying to do that this doesn't work for you?

Comments

0

You can move the code to a named function and call it on resize and when clicking the button.

Or, you can trigger the resize when clicking the button:

$("button").on("click", function(){
   $(window).trigger("resize");
});

Examples: http://jsfiddle.net/cde7fwrb/

EDIT: I see you were talking about the browser maximise button. Oh well....

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.