fader.js 1008 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. if (aFaderItems.length > 1)
  34. {
  35. $(sControlId).html('<li>' + sItemTemplate.replace('%1$s', aFaderItems[0]) + '</li>').show();
  36. fadeOut();
  37. }
  38. }