Advertisement
SlafkoCe

Slider+hover

Dec 14th, 2012
406
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 1.35 KB | None | 0 0
  1. $(function(){
  2.     $(".item").hover(
  3.         function() {
  4.             $(".bottom", this)
  5.             .stop()
  6.             .animate({height: 330 + "px", top: 0 + "px", opacity: 1});
  7.         },
  8.         function() {
  9.             $(".bottom", this)
  10.             .stop()
  11.             .animate({height: 0 + "px", top: 330 + "px", opacity: 0});
  12.         });
  13.     $(".next").click(function(e){
  14.         doSlide("next", this);
  15.         e.preventDefault();
  16.     });
  17.     $(".prev").click(function(e){
  18.         doSlide("prev", this);
  19.         e.preventDefault();
  20.     });
  21.     var doSlide = function(direction, button) {
  22.         next = $(".next"),
  23.         prev = $(".prev"),
  24.         slideWrap = $(button).nextAll('.slide-wrap'),
  25.         slideWidth = $('.item').outerWidth(),
  26.         slideScroll = slideWrap.position().left - slideWidth;
  27.        
  28.         if (direction == "next") {
  29.             if( next.attr('name') == 'next' ) {
  30.             next.removeAttr('name');
  31.             slideWrap.stop().animate({left: slideScroll}, 500, function(){
  32.                 slideWrap
  33.                 .find(".item:first")
  34.                 .appendTo(slideWrap)
  35.                 .parent()
  36.                 .css({'left': 0});
  37.             });
  38.             setTimeout(function(){ next.attr('name','next') }, 600);
  39.         }
  40.         } else if (direction == "prev") {
  41.             if( prev.attr('name') == 'prev' ) {
  42.             prev.removeAttr('name');
  43.             slideWrap
  44.                 .css({'left': slideScroll})
  45.                 .find('.item:last')
  46.                 .prependTo(slideWrap)
  47.                 .parent()
  48.                 .stop()
  49.                 .animate({left: 0}, 500);
  50.                 setTimeout(function(){ prev.attr('name','prev') }, 600);
  51.         }
  52.         }
  53.     };
  54. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement