2012-09-02 91 views
1

的Joomla模块,我想找到一种方法来动态调整基于主含量高的模块数数。这是可能的和如何?在CSS? javascript?调整的基于内容的高度

的目的是为了避免空白页,如果没有内容。

在此先感谢

凡妮莎

+0

你需要某种CSS或JS为父div,使其高度调整accroding它? –

回答

1

这可以以多种方式完成,一些比其他人更优雅。 我能想到的最简单的就是只使用Javascript:

  1. 所有的模块内容都是在HTML中发送的。 (如现在)
  2. 获取主要内容的高度。
  3. 虽然主要内容高于模块高度,但删除最后一个模块。

是这样的:(代码未测试)

window.addEvent('domready', function() { 
    // Get heigth of main content 
    var contentHeight = document.id('content').getHeight(); 

// While the height of the main content is more than 200 
// and less than the height of the modules 
    while(contentHeight > 200 && contentHeight < document.id('modules').getHeight()) { 
     // Get the last module and remove it. 
     $$('#modules .moduletable').getLast().dispose(); 
    } 
}); 

注意,这里假设你使用mootools的(这可能是已经被你的Joomla安装时提供)。另外,我的元素选择器可能无法使用您的模板。

再次,服务器仍然会发送所有模块,即使有些是被删除。另一件事是,当你的网页的DOM完全加载时,这将开始,这意味着用户可能会看到模块消失。因此,在开始时隐藏所有模块也可能更好,然后使用类似的循环逐个显示模块。

编辑: 你可能更喜欢另一个样本。

window.addEvent('domready', function() { 
    // Get heigth of main content 
    var contentHeight = document.id('gkContent').getHeight(); 

    // While the height of the modules is more than 500 
    // and less than the height of the modules 
    while(document.id('gkRight').getHeight() > 500 && contentHeight < document.id('gkRight').getHeight()) { 
     // Get the last module and remove it. 
     var banners = $$('#gkRight .adsense2, #gkRight .bannergroup'); 
     if(banners.length > 0) banners.getLast().dispose(); 
     else break; 
    } 
}); 
+0

嗨 我已经适应了我的网站,但不工作: 你可以看看这个网页:http://www.auxaffaires.fr/index.php/4-sorties-loisirs/143-velorail-du-bourbonnais-offrez –

+0

对不起,我的错!我忘了在“document.id(”modules“)之后添加”.getHeight()“..我已经编辑了答案。 –

+0

好吧,它的工作原理我需要调整一些参数来壮举我的模块,但现在我明白系统非常感谢! –