I want to delay this part of jquery code by 2 seconds
//set equal height of two div's
//$(".pg-right-bar").css({ "height": $("#pg-left-bar").height() })
var leftbar = $(".pg-left-bar").height();
var rightbar = $(".pg-right-bar").height()-4; // remove 4 pxels from righ div
leftbar = leftbar - 20;
if (leftbar > rightbar)
{
$(".pg-right-bar").css({ "height": $("#pg-left-bar").height() - 10 })
}
else
{
$(".pg-left-bar").css({ "height": $("#pg-right-bar").height() })
$(".pg-right-bar").css({ "height": rightbar+"px" })
}
Actually my page has two divs pg-left-bar div
& pg-right-bar div
my left bar div has page contents and right bar div has image. and i have to assign both divs same height depending on which one has greater height.
So i use above logic for this but problem with this code is that it executes before right-bar image is downloaded which results in is that most of the time first condition is true. Is there a way i can delay the execution of this code till image in pg-right-bar
is downloaded.
or how can i wrap this code in a function with 3 seconds delay.
After trouble shooting i came to conclusion that code logic is fine it is the image which take time to download & in between jquery is executed and assign wrong dimensions to both the div
Complete...
jQuery(document).ready(function () {
App.init();
App.initNavMenu();
//Tabs
App.InitCustomTabs();
App.initMarqueeBrands();
//activatte tooltip
$('.tooltip').tooltipster();
});
UPDATE
I solved the problem by wrapping the code in following function.
$(window).load(function() {
var leftbar = $(".pg-left-bar").height();
var rightbar = $(".pg-right-bar").height()-4; // remove 4 pxels from righ div
leftbar = leftbar - 20;
if (leftbar > rightbar)
{
$(".pg-right-bar").css({ "height": $("#pg-left-bar").height() - 10 })
}
else
{
$(".pg-left-bar").css({ "height": $("#pg-right-bar").height() })
$(".pg-right-bar").css({ "height": rightbar+"px" })
}
});