fader.js 972 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. function smc_NewsFader(oOptions)
  2. {
  3. var
  4. aFaderItems = oOptions.aFaderItems || [],
  5. iFadeIndex = 0,
  6. iFadeDelay = oOptions.iFadeDelay || 5000,
  7. iFadeSpeed = oOptions.iFadeSpeed || 650,
  8. sItemTemplate = oOptions.sItemTemplate || '%1$s',
  9. sControlId = '#' + oOptions.sFaderControlId,
  10. fadeIn = function ()
  11. {
  12. iFadeIndex++;
  13. if (iFadeIndex >= aFaderItems.length)
  14. iFadeIndex = 0;
  15. $(sControlId + ' li').html(sItemTemplate.replace('%1$s', aFaderItems[iFadeIndex])).fadeTo(iFadeSpeed, 0.99, function () {
  16. // Restore ClearType in IE.
  17. this.style.filter = '';
  18. fadeOut();
  19. });
  20. },
  21. fadeOut = function ()
  22. {
  23. setTimeout(function ()
  24. {
  25. $(sControlId + ' li').fadeTo(iFadeSpeed, 0, fadeIn);
  26. }, iFadeDelay);
  27. };
  28. if (!aFaderItems.length)
  29. $(sControlId + ' li').each(function ()
  30. {
  31. aFaderItems.push($(this).html());
  32. });
  33. $(sControlId).html('<li>' + sItemTemplate.replace('%1$s', aFaderItems[0]) + '</li>').show();
  34. fadeOut();
  35. }