We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 41970
    • 79 Posts
    Hi have included this slider into my page, but unfortunately it doesn't contain a graphical pagination yet, and I would like to add this feature. I don't really know much about javascript, and I hope that someone here can get me on the right way in implementing this. Here is the slideshow code:

    <script type="text/javascript">
    $(document).ready(function(){
      var currentPosition = 0;
      var slideWidth = 960;
      var slides = $('.slide');
      var numberOfSlides = slides.length;
    
      // Remove scrollbar in JS
      $('#slidesContainer').css('overflow', 'hidden');
    
      // Wrap all .slides with #slideInner div
      slides
        .wrapAll('<div id="slideInner"></div>')
        // Float left to display horizontally, readjust .slides width
    	.css({
          'float' : 'right',
          'width' : slideWidth
        });
    
      // Set #slideInner width equal to total width of all slides
      $('#slideInner').css('width', slideWidth * numberOfSlides);
    
      // Insert controls in the DOM
      $('#contentslider')
        .prepend('<span class="control" id="leftControl">Clicking moves left</span>')
        .append('<span class="control" id="rightControl">Clicking moves right</span>');
    
      // Hide left arrow control on first load
      manageControls(currentPosition);
    
      // Create event listeners for .controls clicks
      $('.control')
        .bind('click', function(){
        // Determine new position
    	currentPosition = ($(this).attr('id')=='rightControl') ? currentPosition+1 : currentPosition-1;
        
    	// Hide / show controls
        manageControls(currentPosition);
        // Move slideInner using margin-left
        $('#slideInner').animate({
          'marginLeft' : slideWidth*(-currentPosition)
        });
      });
    
      // manageControls: Hides and Shows controls depending on currentPosition
      function manageControls(position){
        // Hide left arrow if position is first slide
    	if(position==0){ $('#leftControl').hide() } else{ $('#leftControl').show() }
    	// Hide right arrow if position is last slide
        if(position==numberOfSlides-1){ $('#rightControl').hide() } else{ $('#rightControl').show() }
      }	
    });
    </script>
    



    The slides themselves are within a divs with the class "slide".

    Thank you for your help!

      • 10208 ☆ A M B ☆
      • 1,780 Posts
      If you don't know js well enough to write it yourself, perhaps look into a different slider solution that does what you want out of the box. There are many to choose from out there and that will be a lot easier than reinventing the wheel in js.

      This article/tutorial may be helpful for you:


      https://www.markhamstra.com/modx-blog/2012/04/managing-galleries-with-migx/
        Frogabog- MODX Websites in Portland Oregon
        "Do yourself a favor and get a copy of "MODX - The Official Guide" by Bob Ray. Read it.
        Having server issues? These guys have MODX Hosting perfected - SkyToaster
        • 41970
        • 79 Posts
        Thank you very much, I will definitely look at the link! I finally did solve my slider problem, and got it to work the way I wanted smiley