开发者

Error including two jQuery Cycle plugins in same script? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reason开发者_运维技巧ably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

I have two instances of the jQuery Cycle plugin on the same page. Used in isolation, they both work fine. Used together, I get an error which stops them working.

I don't see how I can use an each() function, seeing as the options are different for the two instances.

$('#preview .cycle').before('<div class="pager">').cycle({ 
    fx:    'fade', 
    speed:  800,
    timeout: 5000,
    pager:  '.pager',
    pauseOnPagerHover: 1
    });

$('#switcher .cycle').before('<div class="pager">').cycle({ 
    fx:    'scrollHorz', 
    speed:  1500,
    timeout: 0,
    pager:  '.pager',
    pauseOnPagerHover: 1
    });

The Javascript console error message shows:

Uncaught TypeError: Cannot read property 'cycleW' of undefined

When used together, the first one works OK but the second throws the error. If used alone, the second works fine.

How can I get the two instances of jQuery Cycle to play nice?


have you tried something like the following?

var countit = 0;
$('.cycle').each(function() {
  var thenav = $('<div class="pager"></div>').insertBefore(this);
  countit++;
  if (countit == 1){
    $(this).cycle({
      fx:    'fade', 
      speed:  800,
      timeout: 5000,
      pager:  thenav,
      pauseOnPagerHover: 1
    });
  } else {
    $(this).cycle({
      fx: 'scrollHorz', 
      speed: 1500,
      timeout: 0,
      pager: thenav,
      pauseOnPagerHover: 1
    });
  }
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜