除非我“检查页面”,否则不会设置高度
由于某种原因,当页面首次加载并且内容调整大小时,如果我在 Chrome 中执行“检查元素”,它只会运行“matchColumns”。似乎无法理解为什么它会这样做,而不是每次内容更改时都更改。 这里是我正在使用的网站。提前致谢。
var $j = jQuery.noConflict();
$j(document).ready(function() {
MC.general.init();
MC.homeSlider.init();
MC.homeMap.init();
$j(window).resize(function() {
$j('#layer-base, #layer-top, .exposed, ').matchColumns();
});
});
$j.fn.matchColumns = function(){
var height_tar = $j(document).height();
$j(this).css({"height": (height_tar ) + "px"});
}; // matchColumns
For some reason this works when the page first loads and when the content gets resized it will only run the "matchColumns" if I do an "inspect element" in chrome. Can't seem to understand why it does that instead of changing everytime the content changes. Here is the site that I am working with. Thanks in advance.
var $j = jQuery.noConflict();
$j(document).ready(function() {
MC.general.init();
MC.homeSlider.init();
MC.homeMap.init();
$j(window).resize(function() {
$j('#layer-base, #layer-top, .exposed, ').matchColumns();
});
});
$j.fn.matchColumns = function(){
var height_tar = $j(document).height();
$j(this).css({"height": (height_tar ) + "px"});
}; // matchColumns
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
检查会在 Chrome/Safari 中打开 Web 检查器或 Firefox 中的 Firebug,它会占用视口的某些部分并触发窗口调整大小事件(即使从文档的角度来看,就操作系统而言窗口尚未更改大小)看来它有)。
除了在调整大小时触发的调用之外,我还添加了对立即运行的 matchColumns 的调用。就像:
或者更好的是,将该行分解成一个函数。
Inspecting opens the Web Inspector in Chrome/Safari or Firebug in Firefox, which takes up some portion of the viewport and triggers a window resize event (even though the window hasn't changed size as far as the OS is concerned, from your document's point of view it has).
I'd add a call to matchColumns that runs right away, in addition to the calls that fire on resize. So like:
Or better, factor out that line into a function.