1
我對響應菜單使用以下腳本。在IE7中,腳本會使頁面凍結,並說該頁面「由於長時間運行的腳本而沒有響應」。我發現造成凍結的位是代碼底部的window.bind
部分,從我的研究到目前爲止,這表明它導致了IE7中的無限循環。我已閱讀關於使用setTimeout等的答案,但我很新手,不知道如何將其實現到腳本中。任何想法如何我可以防止此腳本崩潰/凍結IE7?window.bind函數導致ie7無法響應,因爲長時間運行的腳本
這裏是一個涉及上this blog post超時一個解決方案,但我不知道如何使用我的腳本執行它下面
/* Sample scripts for RWD nav patterns
(c) 2012 Maggie Wachs, Filament Group, Inc - http://filamentgroup.com/examples/rwd-nav- patterns/GPL-LICENSE.txt
Last updated: March 2012
Dependencies: jQuery
*/
jQuery(function($){
$('.nav-primary')
// test the menu to see if all items fit horizontally
.bind('testfit', function(){
var nav = $(this),
items = nav.find('a');
$('body').removeClass('nav-menu');
// when the nav wraps under the logo, or when options are stacked, display the nav as a menu
if ((nav.offset().top > nav.prev().offset().top) || ($(items[items.length-1]).offset().top > $(items[0]).offset().top)) {
// add a class for scoping menu styles
$('body').addClass('nav-menu');
};
})
// toggle the menu items' visiblity
.find('h3')
.bind('click focus', function(){
$(this).parent().toggleClass('expanded')
});
// ...and update the nav on window events
$(window).bind('load resize orientationchange', function(){
$('.nav-primary').trigger('testfit');
});
});
感謝您的信息,雖然我不知道我有知識來執行它與我有什麼。你能給我一個例子在腳本中使用setInterval嗎? – Andrew