Witam,

Chciałbym zmodyfikować standardowy skrypt jcarousellite, aby button, który odpowiada aktywnemu <li> był podświetlony (zmieniony styl). Czyli automatyczne wskazywanie, który <li> jest aktualnie widoczny.

jcarousellite:
  1. (function($) { // Compliant with jquery.noConflict()
  2. $.fn.jCarouselLite = function(o) {
  3. o = $.extend({
  4. btnPrev: null,
  5. btnNext: null,
  6. btnGo: null,
  7. mouseWheel: false,
  8. auto: null,
  9.  
  10. speed: 200,
  11. easing: null,
  12.  
  13. vertical: false,
  14. circular: true,
  15. visible: 3,
  16. start: 0,
  17. scroll: 1,
  18.  
  19. beforeStart: null,
  20. afterEnd: null
  21. }, o || {});
  22.  
  23. return this.each(function() { // Returns the element collection. Chainable.
  24.  
  25. var running = false, animCss=o.vertical?"top":"left", sizeCss=o.vertical?"height":"width";
  26. var div = $(this), ul = $("ul", div), tLi = $("li", ul), tl = tLi.size(), v = o.visible;
  27.  
  28. if(o.circular) {
  29. ul.prepend(tLi.slice(tl-v-1+1).clone())
  30. .append(tLi.slice(0,v).clone());
  31. o.start += v;
  32. }
  33.  
  34. var li = $("li", ul), itemLength = li.size(), curr = o.start;
  35. div.css("visibility", "visible");
  36.  
  37. li.css({overflow: "hidden", float: o.vertical ? "none" : "left"});
  38. ul.css({margin: "0", padding: "0", position: "relative", "list-style-type": "none", "z-index": "1"});
  39. div.css({overflow: "hidden", position: "relative", "z-index": "2", left: "0px"});
  40.  
  41. var liSize = o.vertical ? height(li) : width(li); // Full li size(incl margin)-Used for animation
  42. var ulSize = liSize * itemLength; // size of full ul(total length, not just for the visible items)
  43. var divSize = liSize * v; // size of entire div(total length for just the visible items)
  44.  
  45. li.css({width: li.width(), height: li.height()});
  46. ul.css(sizeCss, ulSize+"px").css(animCss, -(curr*liSize));
  47.  
  48. div.css(sizeCss, divSize+"px"); // Width of the DIV. length of visible images
  49.  
  50. if(o.btnPrev)
  51. $(o.btnPrev).click(function() {
  52. return go(curr-o.scroll);
  53. });
  54.  
  55. if(o.btnNext)
  56. $(o.btnNext).click(function() {
  57. return go(curr+o.scroll);
  58. });
  59.  
  60. if(o.btnGo)
  61. $.each(o.btnGo, function(i, val) {
  62. $(val).click(function() {
  63. return go(o.circular ? o.visible+i : i);
  64. });
  65. });
  66.  
  67. if(o.mouseWheel && div.mousewheel)
  68. div.mousewheel(function(e, d) {
  69. return d>0 ? go(curr-o.scroll) : go(curr+o.scroll);
  70. });
  71.  
  72. if(o.auto)
  73. setInterval(function() {
  74. go(curr+o.scroll);
  75. }, o.auto+o.speed);
  76.  
  77. function vis() {
  78. return li.slice(curr).slice(0,v);
  79. };
  80.  
  81. function go(to) {
  82. if(!running) {
  83.  
  84. if(o.beforeStart)
  85. o.beforeStart.call(this, vis());
  86.  
  87. if(o.circular) { // If circular we are in first or last, then goto the other end
  88. if(to<=o.start-v-1) { // If first, then goto last
  89. ul.css(animCss, -((itemLength-(v*2))*liSize)+"px");
  90. // If "scroll" > 1, then the "to" might not be equal to the condition; it can be lesser depending on the number of elements.
  91. curr = to==o.start-v-1 ? itemLength-(v*2)-1 : itemLength-(v*2)-o.scroll;
  92. } else if(to>=itemLength-v+1) { // If last, then goto first
  93. ul.css(animCss, -( (v) * liSize ) + "px" );
  94. // If "scroll" > 1, then the "to" might not be equal to the condition; it can be greater depending on the number of elements.
  95. curr = to==itemLength-v+1 ? v+1 : v+o.scroll;
  96. } else curr = to;
  97. } else { // If non-circular and to points to first or last, we just return.
  98. if(to<0 || to>itemLength-v) return;
  99. else curr = to;
  100. } // If neither overrides it, the curr will still be "to" and we can proceed.
  101.  
  102. running = true;
  103.  
  104. ul.animate(
  105. animCss == "left" ? { left: -(curr*liSize) } : { top: -(curr*liSize) } , o.speed, o.easing,
  106. function() {
  107. if(o.afterEnd)
  108. o.afterEnd.call(this, vis());
  109. running = false;
  110. }
  111. );
  112. // Disable buttons when the carousel reaches the last/first, and enable when not
  113. if(!o.circular) {
  114. $(o.btnPrev + "," + o.btnNext).removeClass("disabled");
  115. $( (curr-o.scroll<0 && o.btnPrev)
  116. ||
  117. (curr+o.scroll > itemLength-v && o.btnNext)
  118. ||
  119. []
  120. ).addClass("disabled");
  121. }
  122.  
  123. }
  124. return false;
  125. };
  126. });
  127. };
  128.  
  129. function css(el, prop) {
  130. return parseInt($.css(el[0], prop)) || 0;
  131. };
  132. function width(el) {
  133. return el[0].offsetWidth + css(el, 'marginLeft') + css(el, 'marginRight');
  134. };
  135. function height(el) {
  136. return el[0].offsetHeight + css(el, 'marginTop') + css(el, 'marginBottom');
  137. };
  138.  
  139. })(jQuery);


kod html:

  1. <div class="carousel">
  2. <ul>
  3. <li><div id="incarousel"><p>hghjhjhjkjk</p></div></li>
  4. <li><div id="incarousel"><p>test test</p></div></li>
  5. </ul></div>
  6. <div class="buttony"><button class="1" id="widac_1">1</button><button class="2" id="widac_2">2</button></div><script type="text/javascript">
  7.  
  8. $(function() {
  9. $(".carousel").jCarouselLite({
  10. btnNext: ".buttony .next",
  11. btnPrev: ".buttony .prev",
  12. visible: 1,
  13. auto: 5000,
  14. speed: 0,
  15. btnGo:
  16. [".buttony .1", ".buttony .2" ]
  17. });
  18. });
  19. </script>


Dokładne działanie, o które mi chodzi jest np. na Onecie - strona główna, pod reklamą, na środku - są tam kropki, które są normalnie przezroczystobiałe, a kiedy odpowiednia treść się wyświetla, jedna z nich jest żółta.

Proszę o pomoc, co mam dodać do javascript, żeby odpowiedni button był podświetlony, kiedy odpowiednia treść wyświetla się w karuzeli?

czy ktoś może mi pomóc?