1

I have the following code:

  front_page_magic();

  $(window).resize(function() {
    front_page_magic();
  });   

All the magic happens within front_page_magic(), although whenever I load the page the resize function also gets called which creates some whacky and slow behaviour as the function is been called twice in quick succession.

Is this something which is related to certain browsers too?

I though $(window).resize() was only relative to the resizing of the browser window, and had nothing to do with page load/refresh?

Rick Donohoe
  • 7,081
  • 6
  • 26
  • 38

2 Answers2

1

To answer your question. Nope. It's not supposed to trigger unless you have a resize event which you either trigger resizing your browswer or triggering it manually.

The one thing you definitely want to look for are things like calling the file more than once, initializing the method more than once, binding that method somewhere else, or triggering the resize event manually.

This answer may be related.

jQuery resize function doesn't work on page load

Community
  • 1
  • 1
Eric C
  • 2,195
  • 1
  • 17
  • 23
0

the code executes everytime the page load because you havefront_page_magic();in there

Anders R. Bystrup
  • 15,729
  • 10
  • 59
  • 55