2012-04-27 78 views
0

您好......我遇到了一個問題,使用jQuery的縮略圖滾動。它與Fancybox以及我一直基於onload事件使用的另一個腳本衝突。我發現這個功能,使多個的onload事件由西蒙·威爾遜火:多重負載衝突


function func1() { 
    alert("This is the first."); 
} 
function func2() { 
    alert("This is the second."); 
} 

function addLoadEvent(func) { 
    var oldonload = window.onload; 
    if (typeof window.onload != 'function') { 
    window.onload = func; 
    } else { 
    window.onload = function() { 
     if (oldonload) { 
     oldonload(); 
     } 
     func(); 
    } 
    } 
} 
addLoadEvent(func1); 
addLoadEvent(func2); 
addLoadEvent(function() { 

I WANT TO INSERT THE FOLLOWING JQUERY FUNCTION HERE 

}) 

我的問題現在越來越第三功能才能正常工作。這是一個語法問題。

這裏是我的jQuery要插入:

jQuery.noConflict(); 
(function($){ 
window.onload=function(){ 
    $("#tS3").thumbnailScroller({ 
     scrollerType:"hoverPrecise", 
     scrollerOrientation:"vertical", 
     scrollSpeed:2, 
     scrollEasing:"easeOutCirc", 
     scrollEasingAmount:800, 
     acceleration:4, 
     scrollSpeed:800, 
     noScrollCenterSpace:10, 
     autoScrolling:0, 
     autoScrollingSpeed:2000, 
     autoScrollingEasing:"easeInOutQuad", 
     autoScrollingDelay:500 
    }); 
} 
})(jQuery); 

任何建議非常感謝!

回答

1

試試這個:

function func1() { 
    alert("This is the first."); 
} 
function func2() { 
    alert("This is the second."); 
} 

function addLoadEvent(func) { 
    var oldonload = window.onload; 
    if (typeof window.onload != 'function') { 
    window.onload = func; 
    } else { 
    window.onload = function() { 
     if (oldonload) { 
     oldonload(); 
     } 
     func(); 
    } 
    } 
} 
addLoadEvent(func1); 
addLoadEvent(func2); 
addLoadEvent(function() { 
    $("#tS3").thumbnailScroller({ 
     scrollerType:"hoverPrecise", 
      scrollerOrientation:"vertical", 
      scrollSpeed:2, 
      scrollEasing:"easeOutCirc", 
      scrollEasingAmount:800, 
      acceleration:4, 
      scrollSpeed:800, 
      noScrollCenterSpace:10, 
      autoScrolling:0, 
      autoScrollingSpeed:2000, 
      autoScrollingEasing:"easeInOutQuad", 
      autoScrollingDelay:500 
     }); 
}) 

你的問題是,您試圖添加的功能是專門覆蓋window.onload有其自身的功能,而不是追加本身喜歡它的目的是。

+0

感謝布萊爾......它適用於前兩種功能,但仍然不火的第三個功能。它與jQuery無衝突規則有關。以下是我以第三種方式運行腳本的全部內容: – bpok 2012-04-28 03:26:49

+0

*請參閱最初的問題,我添加了jQuery.noConflict();在我需要插入的函數上方行! – bpok 2012-04-28 03:33:14

+0

已修復。感謝布萊爾......我只是改變了順序,並刪除了衝突的插件。 – bpok 2012-04-28 14:15:53

1

爲什麼你需要這樣做?爲什麼你需要排隊這樣的onload處理程序?既然你已經在使用jQuery,爲什麼還要使用本地處理程序呢?

function func1() { ... } 
function func2() { ... } 
function thumbScroller() { 
$("#tS3").thumbnailScroller({ 
     scrollerType:"hoverPrecise", 
     scrollerOrientation:"vertical", 
     scrollSpeed:2, 
     scrollEasing:"easeOutCirc", 
     scrollEasingAmount:800, 
     acceleration:4, 
     scrollSpeed:800, 
     noScrollCenterSpace:10, 
     autoScrolling:0, 
     autoScrollingSpeed:2000, 
     autoScrollingEasing:"easeInOutQuad", 
     autoScrollingDelay:500 
    }); 
} 

現在叫他們都集體

jQuery(document).ready(function() { 
    func1(); 
    func2(); 
    thumbScroller(); 
});