[Solved] Div is showing with delay of 2-3 seconds on a CMS after height change, Is there alternative [closed]


I’m going to guess that by “slow” you mean it doesn’t happen until the div has already been visible for a while.

The reason is that you’re using the load event, which doesn’t happen until very late in the page load cycle.

If you want to change the height as soon as possible, put your script tag at the bottom of the page and do it immediately, without waiting for load.

If you can’t put your script tag at the bottom of the page (some CMS’s are difficult), you can use jQuery’s ready callback, which happens much sooner than load:

    $(myWindow.Resize);

Side note: Your resize handler hookup is incorrect:

$(window).resize(myWindow.Resize());
// Remove these ----------------^^

With the () there, you’re calling myWindow.Resize() and passing its return value (undefined) into $(window).resize(...), exactly the way foo(bar()) calls bar and passes its return value into foo.


Also note that your setHeight function just won’t work at all. You’re using getElementsByClassName and then assigning to a height property on what you get back. But what you get back is a collection of elements, not a single element, and that collection doesn’t have a height property.

The commented-out jQuery line above where you call setHeight would work.

1

solved Div is showing with delay of 2-3 seconds on a CMS after height change, Is there alternative [closed]