2012-04-27 75 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(); 
});