[英]JQuery Function not firing on page load it works only after i refresh page or re-visit the same page again
I need to give two div's pg-left-bar
and pg-right-bar
equal height based on which div is larger. 我需要基于两个div较大的两个div的
pg-left-bar
和pg-right-bar
高度相等。
I have following jQuery code block and you can find following code log which i use to check div height. 我有以下jQuery代码块,您可以找到以下代码日志来检查div的高度。
Jquery doesnt seem to work if pg-right-bar
has more height than pg-left-bar
if i am visiting the page first time only and if i refresh or visit the same page again it works and gives both dives equal height. 如果
pg-right-bar
高度比pg-left-bar
高度高,如果我仅第一次访问该页面,并且如果刷新或再次访问同一页面,则jquery似乎不起作用,并且可以使两个潜水高度相等。
I also tried be call do this in $(window).load(function () {})
but doesnt not make any different. 我也尝试在
$(window).load(function () {})
调用此方法,但没有任何区别。
I am using asp.net web form master page for my design. 我正在使用asp.net Web表单母版页进行设计。 I would appreciate help in this regard.
在此方面的帮助,我将不胜感激。
jQuery(document).ready(function () {
App.init();
App.initNavMenu();
//Tabs
App.InitCustomTabs();
App.initMarqueeBrands();
//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" })
}
//activatte tooltip
$('.tooltip').tooltipster();
});
Well I got the general gist of your question but the entire question description is pretty confusing so I'll try to just help you out where I think it counts. 好吧,我很了解您的问题,但是整个问题的描述都令人困惑,因此,我将尽力帮助您解决我认为很重要的问题。
var leftbar = $(".pg-left-bar").height();
var rightbar = $(".pg-right-bar").height();
if (leftbar >= rightbar) {
$(".pg-right-bar").css({ "height": leftbar + "px" })
}else{
$(".pg-left-bar").css({ "height": rightbar + "px" })
}
I omitted your magic numbers and the other code to make the change apparent but I think your issue was due to the lack of "px" being concatenated to the ends of your css declarations. 我省略了您的幻数和其他代码以使更改显而易见,但我认为您的问题是由于缺少“ px”并连接到css声明的末尾。 If this isn't the issue would you mind showing a full example.
如果不是这个问题,您可以举一个完整的例子。
Make sure none of the App init calls generates any exceptions. 确保没有任何应用程序初始化调用会生成任何异常。 Then try if this helps:
然后尝试这样做是否有帮助:
$(function () {
App.init();
App.initNavMenu();
//Tabs
App.InitCustomTabs();
App.initMarqueeBrands();
//set equal height of two div's
var leftbar = $(".pg-left-bar :first").height() - 20;
var rightbar = $(".pg-right-bar :first").height() - 4; // remove 4 pxels from righ div
if (leftbar > rightbar)
{
leftbar = leftbar + 10;
$(".pg-right-bar").css({ "height": leftbar });
$(".pg-left-bar").css({ "height": leftbar });
}
else
{
$(".pg-left-bar").css({ "height": rightbar});
$(".pg-right-bar").css({ "height": rightbar });
}
//activatte tooltip
$('.tooltip').tooltipster();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.