2013-10-22 41 views
0

我遇到了一個高度相同的腳本問題,這使得我的4個div的行高度相等。在一個div中,我有neosmart-stream,它在div中加載了我最新的facebook文章。其他div應該與高度匹配,問題在於div高度與首先加載的最高div相匹配,其中包含目錄圖片。加載一個函數,接着加載

我希望能夠在我的Facebook發佈後加載運行等高度腳本。 以下是該網站的鏈接:http://www.guitarworldcityarcade.com.au/ 它適用於旋轉橫幅下面的4個深灰色框。

對不起,我沒有提供代碼的大錯誤。下面是相等的高度代碼:

<script> 
    equalheight = function(container){ 

var currentTallest = 0, 
    currentRowStart = 0, 
    rowDivs = new Array(), 
    $el, 
    topPosition = 0; 
$(container).each(function() { 

    $el = $(this); 
    $($el).height('auto') 
    topPostion = $el.position().top; 

    if (currentRowStart != topPostion) { 
    for (currentDiv = 0 ; currentDiv < rowDivs.length ; currentDiv++) { 
     rowDivs[currentDiv].height(currentTallest); 
    } 
    rowDivs.length = 0; // empty the array 
    currentRowStart = topPostion; 
    currentTallest = $el.height(); 
    rowDivs.push($el); 
    } else { 
    rowDivs.push($el); 
    currentTallest = (currentTallest < $el.height()) ? ($el.height()) : (currentTallest); 
    } 
    for (currentDiv = 0 ; currentDiv < rowDivs.length ; currentDiv++) { 
    rowDivs[currentDiv].height(currentTallest); 
    } 
}); 
} 

$(window).load(function() { 
    equalheight('.module'); 
}); 

$(window).resize(function(){ 
    equalheight('.module'); 
}); 
    </script> 

這裏是爲Facebook的職位代碼:

<div class="module"> 

<h1>News</h1> 

<script type='text/javascript' src='http://www.guitarworldcityarcade.com.au/neosmart-stream/nss-includes/jquery.js'></script> 

<script type='text/javascript' src='http://www.guitarworldcityarcade.com.au/neosmart-stream/nss-core/jquery.neosmart.stream.js'></script> 

<link href='http://www.guitarworldcityarcade.com.au/neosmart-stream/nss-core/core.css' type='text/css' rel='stylesheet' /> 

<link href='http://www.guitarworldcityarcade.com.au/neosmart-stream/nss-content/themes/base/style.css' type='text/css' rel='stylesheet' /> 

<script type='text/javascript'>(function(window){window.onload=function(){jQuery(function(){jQuery('#nss').neosmartStream({introFadeIn:695,masonry:false,cache_time:60,theme:'base',path:'http://www.guitarworldcityarcade.com.au/neosmart-stream/',channel_group:'all',auto_refresh:true,auto_refresh_time:60})})}})(window);</script> 

這僅僅是一些腳本,facebook的帖子是一個插件。這四個div具有.module類

一個有window.load(function())和另一個window.onload = function(),它們會發生衝突嗎?有沒有辦法讓我可以在另一個之後加載這麼多毫秒?

+3

你有密碼嗎?我們可以在這裏看到,而不是在您的網站上查找 –

+0

您可能需要找到正確的'load'事件來偵聽並運行您的腳本,但是我建議您發佈如何加載facebook文章以便我們可以看看可能的選擇。 – jfriend00

+0

如果該neosmart-stream支持事件,則可以偵聽一個加載事件並運行等高度腳本。 – Todd

回答

0

我用這個騙了一點。調整大小腳本在頁面加載和調整大小時激活。所以我添加了另一個事件偵聽器,以便在用戶向下滾動時激活腳本。這是可行的,因爲調整大小的方塊在所有屏幕和設備上都低於所有屏幕(除了特別長的屏幕,但是你經常遇到它們嗎?) 我得弄清楚它的正確性,但現在可以使用。

0

我不知道你現在的代碼是什麼,因爲你沒有發佈任何代碼片段,但你可能只是想嘗試經典的表。或者,您可能想嘗試將每個容器設置爲100%高度(css)並讓它們彼此相鄰浮動。如果這不能解決你的問題,你可能想用一些代碼片段來改進你的問題,而不是讓我們做所有的工作。

0

如果您使用的是Facebook Javascript SDK,那麼您應該可以使用異步代碼並指定您的高度函數在window.fbAsyncInit函數中運行。但是,您仍然需要等待,然後才能知道您所處的真實高度,然後才能應用CSS和樣式。

window.fbAsyncInit = function() { 
    // init the FB JS SDK 
    FB.init({ 
     appId  : 'YOUR_APP_ID',      // App ID from the app dashboard 
     channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel file for x-domain comms 
     status  : true,         // Check Facebook Login status 
     xfbml  : true         // Look for social plugins on the page 
    }); 

    // Additional initialization code such as adding Event Listeners goes here 
}; 
0

如果你使用jQuery,您可以收起你的大小調整腳本$(window).load事件中,像這樣:

$(window).load(function(){ 
    // Your resize code 
}); 

這樣一來,瀏覽器等待整個頁面(圖形,圖像,和iframe)加載之前,它會觸發您的調整腳本。

這意味着如果有任何事情被掛起 - 比如說用戶在2G網絡上,或者外部資源無法加載 - 那麼您的盒子將永遠不會調整大小。不過,我之前使用過它,只要知道風險,它就是一個簡單快速的修復方法。