我是一個JS/JQ noob嘗試延遲某些元素的加載,直到頁面的其餘部分加載完畢。使用Jquery延遲加載特定元素
具體來說,每個頁面有幾個列表,其中包含社交媒體iframes /遠程腳本作爲列表項目,並且其url是使用php生成的。
我最好的猜測會是這樣的(內置):
$(document).ready(function(){
$('ul.post-meta-bottom').append('
<li class="like-button">
<iframe class="fblikebutton" src="http://www.facebook.com/plugins/like.php?href=<?php echo urlencode($this_permalink); ?>&layout=button_count&show-faces=false&width=80&action=like&colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="overflow:hidden; width:80px; height:30px"></iframe>
</li><!--like-button-->
<li class="tweet-button">
<a href="http://twitter.com/share" class="twitter-share-button" data-url="<?php echo $this_permalink; ?>" data-text="<?php echo $this_title; ?>" data-count="horizontal" data-via="" data-related="">Tweet</a>
<script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
</li><!--tweet-button-->
<li class="reddit-button">
<script type="text/javascript">
reddit_url = "<?php echo urlencode($this_permalink); ?>";
reddit_title = "<?php echo $this_title; ?>";
reddit_target= "gaming";
</script>
<script type="text/javascript" src="http://www.reddit.com/static/button/button1.js"></script>
</li><!--reddit-button-->
')
});
...這不工作,我肯定是不這樣做,無論如何最好的辦法。
有人幫忙嗎?謝謝!
不,這不會工作,因爲js是客戶端。所有這些php元素都在服務器端進行評估。只需將這些元素放在.php文件中,並在客戶端查看頁面時加載它們。爲了延緩php的負載,你應該問php的傢伙。 –
你能發佈整個頁面源嗎? –
@Joseph 我打算把這個內聯,所以PHP會在JS之前完成這件事情。 – Jartron