jQuery Tutorial – Create a jQuery Menu Slider


SUBMITTED BY: jlolk3r

DATE: Jan. 19, 2016, 6:26 a.m.

FORMAT: JavaScript

SIZE: 1.1 kB

HITS: 1016

  1. $(document).ready(function() {
  2. // Declare variables
  3. var direction = 'vertical'; // Additional variable which determines the slider direction - vertical or horizontal
  4. var width = 400;
  5. var height = 292; // Declare the height of the slider panel
  6. var slides = $('#list-images li');
  7. var numSlides = slides.length;
  8. // Set CSS of slide-wrap based on direction
  9. wrapCss = direction == 'vertical' ? {height: height * numSlides} : {width: width * numSlides} ;
  10. // Wrap the slides & set the wrap width
  11. slides.wrapAll('<div id="slide-wrap"></div>').css({'float' : 'left','width' : width});
  12. $('#slide-wrap').css(wrapCss);
  13. // Hover function - animate the slides based on index of links
  14. $('#list-links li a').hover(function(){
  15. $('#list-links li').removeClass('hover');
  16. var i = $(this).index('#list-links li a');
  17. $(this).parent().addClass('hover');
  18. // Set animation based on direction
  19. params = direction == 'vertical' ? {'marginTop' : height*(-i)} : {'marginLeft' : width*(-i)} ;
  20. $('#slide-wrap').stop().animate(params);
  21. });
  22. });

comments powered by Disqus