2012-09-17 2 views

답변

2

http://jsfiddle.net/ARTsinn/MvRdD/890/

$(document).ready(function() { 
    $.getScript("https://raw.github.com/danro/easing-js/master/easing.min.js"); 
    var animateTime = 10, 
     offsetStep = 5, 
     scrollWrapper = $('#wrap'); 

    //event handling for buttons "left", "right" 
    var aktiv; 
    $('.bttL, .bttR').mousedown(function(e) { 
     if (e.target.className === 'bttR') { 
      aktiv = window.setInterval(function() { 
       scrollWrapper.animate({ 
        scrollLeft: '+=' + 20 
       }, { 
        duration: 600, 
        queue: false, 
        easing: 'easeOutCirc' 
       }); 
      }, 10); 
     } else if (e.target.className === 'bttL') { 
      aktiv = window.setInterval(function() { 

       scrollWrapper.animate({ 
        scrollLeft: '-=' + 20 
       }, { 
        duration: 1200, 
        queue: false, 
        easing: 'easeOutCirc' 
       }); 
      }, 10); 

     } 
    }).mouseup(function() { 
     window.clearInterval(aktiv); 
    }); 


    scrollWrapper.mousedown(function(event) { 
     $(this).data('down', true).data('x', event.clientX).data('scrollLeft', this.scrollLeft); 
     return false; 
    }).mouseup(function(event) { 
     $(this).data('down', false); 
    }).mousemove(function(event) { 
     if ($(this).data('down')) { 
      $(this).stop(false, true).animate({ 
       scrollLeft: $(this).data('scrollLeft') + ($(this).data('x') - event.clientX) * 2 
      }, { 
       duration: 600, 
       queue: false, 
       easing: 'easeOutCirc' 
      }); 
     } 
    }).mousewheel(function(event, delta) { 
     $(this).stop(false, true).animate({ 
      scrollLeft: '-=' + delta * 60 
     }, { 
      duration: 400, 
      queue: false, 
      easing: 'easeOutCirc' 
     }); 
     event.preventDefault(); 
    }).css({ 
     'overflow': 'hidden', 
     'cursor': '-moz-grab' 
    }); 
}); 
+0

아 안돼,이 굉장합니다! 드래그 앤 마우스 휠에서는 쉽게되지만 버튼 프레스에서는 그렇지 않습니다. – legoman

+0

그건 이제 약간의 자바 스크립트를 배우는 당신의 부분 :) 만약 당신이 30 분 이상 실패하면, 다시 쓰기 만하면이 부분도 당신을 위해 완료 할 것입니다 : - – yckart

+0

그것은 내일있을 테지만 나와 함께 곰! – legoman

관련 문제