我在找的東西類似於jQuery image lazy load plugin,但iframe
s。延遲加載iframe(延遲src http調用)與jquery
15
A
回答
21
這對我有效。
var iframes = $('iframe');
$('button').click(function() {
iframes.attr('src', function() {
return $(this).data('src');
});
});
iframes.attr('data-src', function() {
var src = $(this).attr('src');
$(this).removeAttr('src');
return src;
});
0
您可以始終將src屬性初始化爲about:blank,然後當點擊事件觸發時,將src屬性設置爲您要導航到的URL。
+0
iframe的src'在DOM的HTML中被硬編碼,並且不想通過用about:blank代替它來執行太多的DOM操作,然後用URL替換它(它需要被存儲爲一個變量)。 – Steve
0
3
一個similar question是最近使用的技術。我打電話Lazy Loading of iFrames公佈具體到基於引導,Twitter的標籤,這是我answered iFrame中。 js/jquery如下;看到完整的代碼,包括在小提琴或我到OP響應HTML標記:
<script>
$('#myTabs').bind('show', function(e) {
// identify the tab-pane
paneID = $(e.target).attr('href');
// get the value of the custom data attribute to use as the iframe source
src = $(paneID).attr('data-src');
//if the iframe on the selected tab-pane hasn't been loaded yet...
if($(paneID+" iframe").attr("src")=="")
{
// update the iframe src attribute using the custom data-attribute value
$(paneID+" iframe").attr("src",src);
}
});
</script>
0
如果你想這樣做,在WordPress
這裏是一個自動的,要求降低,解決
在WordPress插件形式
這裏是一個WordPress插件,您可以手動下載和通過WordPress插件庫安裝。我今天創建這個只是爲了處理這種情況。不需要對內容進行任何更改,只要在任何和所有內聯框架上激活,就會自動運行。
相關問題
- 1. jquery iframe src加載延遲
- 2. 的jquery - 延遲加載 - 設置延遲
- 3. iframe的延遲加載?
- 4. 延遲加載
- 5. 延遲加載
- 6. 延遲加載
- 7. jquery頁面加載延遲
- 8. RecyclerView延遲加載
- 9. nhibernate延遲加載
- 10. 加載動畫與延遲
- 11. 延遲加載與淡入
- 12. 延遲加載與RequestFactory
- 13. iframe延遲調整大小
- 14. Facebook的飼料iframe延遲加載
- 15. 延遲加載DLL
- 16. 延遲加載XmlDocument
- 17. Laravel延遲加載
- 18. Firebase延遲加載
- 19. jQuery的:延遲加載與carouFredSel插件
- 20. Firebase延遲加載
- 21. UIwebview延遲加載
- 22. 延遲加載MirrorType
- 23. 延遲加載MEF?
- 24. 在featherlight.js中延遲加載iframe
- 25. 延遲加載3.2.6
- 26. 延遲加載CollectionViewSource?
- 27. gwt延遲加載
- 28. 延遲調用
- 29. 延遲加載在highcharts
- 30. 在懸停延遲中添加延遲
最好的辦法是不只是在iframe添加到DOM,直到要加載它,沒有混亂的機會,然後... – DaveRandom
IFrame,這是硬編碼到DOM。我沒有選擇手動插入它們,否則這將是最簡單的路線。 – Steve