#1
  1. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,653
    Rep Power
    171

    Can I stop script's delay?


    Hi;

    I use this to automatically adjust the height of a column. It works fine but has about 1 second delay. Can I somehow get rid of the delay?
    javascript Code:
    <script type="text/javascript">
     
    //Initial load of page
    $(document).ready(sizeContent);
    //Every resize of window
    $(window).resize(sizeContent);
    //Dynamically assign height
    function sizeContent() {
     
    	// Decide which menu is the tallest
    	if ($("#main-menu").height() >= $("#sub-menu").height() && $("#main-menu").height() >= $(".sub-menu2").height()) {
    		var menuHeight = $("#main-menu").height() + 80;
    	}else if($("#sub-menu").height() >= $("#main-menu").height() && $("#sub-menu").height() >= $(".sub-menu2").height()) {
    		var menuHeight = $("#sub-menu").height() + 110;
    	}else if($(".sub-menu2").height() >= $("#main-menu").height() && $(".sub-menu2").height() >= $("#sub-menu").height()) {
    		var menuHeight = $(".sub-menu2").height() + 140;
    	}
     
    	// Set the new height of the menu columns
    	if ($(".wrapper").height() <= $(window).height() && menuHeight <= $(window).height()) {
    		var newHeight = ($(window).height()) + "px";
    	}else if ($(".wrapper").height() <= $(window).height() && menuHeight > $(window).height()) {
    		var newHeight = menuHeight + "px";
    	}else{
    		if ($(".wrapper").height() <= menuHeight) {
    			var newHeight = menuHeight + "px";
    		}else{
    			var newHeight = $(".wrapper").height() + "px";
    		};
    	};
    	$(".tactify-menu-container").css("height", newHeight);
    	$(".tactify-sub-menu-container").css("height", newHeight);
     
    	//Reset some stuff at breakpoint
    	if ($(window).width() > 991) {
    		$(".right-container").css("height", newHeight);
    		$(".wrapper").css("width", "100%");
    	}else{
    		$(".right-container").css("height", "auto");
    	};
    }
    $(document).ready(function() {
    	$('.tactify-menu-button').click(function(){
    		var newWidth = ($(window).width()) + "px";
    		$(".wrapper").css("width", newWidth);
    	    $('.wrapper').toggleClass("slide-over");
     
    	    sizeContent();
    	});
    });
    </script>
  2. #2
  3. A Not To Shabby Code Smurf
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2008
    Posts
    1,127
    Rep Power
    119
    Originally Posted by English Breakfast Tea
    Can I somehow get rid of the delay?
    In short..., "no"; the reason being $(document).ready is equivalent to a readyState of "interactive" and I think..., this state is the earliest event cross-browser (the earliest detectable state across the majority of common browsers, that are currently trending in common usage). From my experience of testing the readyState/.ready() API cross-browser; this seems to be the consistent result. You could try an anonymous function; it's possible (not guaranteed); that it may be milliseconds faster.
    Last edited by web_loone08; January 1st, 2014 at 11:31 PM. Reason: Added An Additional Thought

IMN logo majestic logo threadwatch logo seochat tools logo