2012-01-17 5 views
0

jScrollPane을 사용하여 가로 이미지 슬라이더를 구현하고 horizontalDragMinWidth 설정을 사용하여 드래그 핸들 (.jspDrag)의 최소 폭을 63으로 설정하려고합니다.jScrollPane의 드래그 핸들 크기 조정

불행히도 그것은 제대로 작동하지 않으며 나는 그 이유를 모른다. 나는 정말로 도움이된다.

문제는 http://tmcdomains.com/jScrollPane/static.html에서 볼 수 있습니다. 두 번 JScrollPane의 초기화하는 이유

<script type="text/javascript"> 
$(function() { 
$("img").wrap('<div class="item" />'); 
var $conveyor = $("#conveyor"); 
var $item = $(".item", $conveyor); 
var $viewer = $("#viewer"); 
var api = $viewer.bind("jsp-scroll-x").jScrollPane({animateScroll: true,horizontalDragMinWidth: 63}).data("jsp"); 

var imagesWidth = 0; 
$($item).each(function (index, image) { 
    var $image = $(image); 
    imagesWidth += $image.outerWidth() + parseInt($item.css("margin-right"), 10); 
}); 
$($conveyor).width(imagesWidth); 

function scrollByItem(direction) { 
    var xPos = api.getContentPositionX(); 
    var viewerHalfWidth = $viewer.width()/2; 
    var pixels = 0; 
    $($item).each(function (i) { 
     pixels += $(this).outerWidth(true); 
     if (pixels >= (xPos + viewerHalfWidth)) { 
      if (direction == "right" && $item[i + 1]) { 
       api.scrollToX(($($item[i + 1]).outerWidth(true)/2) + pixels - viewerHalfWidth, true); 
      } else { 
       if (direction == "left" && $item[i - 1]) { 
        api.scrollToX(pixels - $(this).outerWidth(true) - viewerHalfWidth - ($($item[i - 1]).outerWidth(true)/2), true); 
       } 
      } 
      return false; 
     } 
    }); 
    return false; 
} 
$("#prev").click(function() { 
    scrollByItem("left"); 
}); 
$("#next").click(function() { 
    scrollByItem("right"); 
}); 

$viewer.each(
    function() 
    { 
     $(this).jScrollPane(); 
     var api = $(this).data('jsp'); 
     var throttleTimeout; 
     $(window).bind(
      'resize', 
      function() 
      { 
       if ($.browser.msie) { 
        // IE fires multiple resize events while you are dragging the browser window which 
        // causes it to crash if you try to update the scrollpane on every one. So we need 
        // to throttle it to fire a maximum of once every 50 milliseconds... 
        if (!throttleTimeout) { 
         throttleTimeout = setTimeout(
          function() 
          { 
           api.reinitialise(); 
           throttleTimeout = null; 
          }, 
          50 
         ); 
        } 
       } else { 
        api.reinitialise(); 
       } 
      } 
     ); 
    } 
);  

}); 
</script> 
+0

무엇이 잘못되었는지 디버깅하려면 jscrollpane.min.js를 비공식 버전으로 바꾸실 수 있습니까? –

+0

jscrollpane.js의 비공식 버전을 호출하도록 파일을 업데이트했습니다 ... 감사합니다. Grace =) – tmc

답변

1

내가 확실히 이해 해달라고 :

처음 :

var api = $viewer.bind("jsp-scroll-x").jScrollPane({animateScroll: true,horizontalDragMinWidth: 63}).data("jsp"); 

다음 스크립트는 바로 태그를, 내 바닥 글에 시간 :

$(this).jScrollPane(); 

하지만 디버깅을 마친 후. jScrollPane가 두 번 초기화되었습니다 (jScrollPane.js의 448 행에서 453 행까지 두 번 실행 됨). 두 번째로 초기화 될 때 horizontalDragMinWidth이 설정의 일부로 지정되지 않으므로 horizontalDragMinWidth는 기본적으로 0입니다. 나의 직감은 이것이 문제라는 것이다.

+0

안녕하세요, 귀하의 의견에 많은 감사를드립니다. 내 jQuery 기술은 기존 플러그인을 사용하고, 일부 물건을 변경하고, 내 손가락을 교차 시키면 작동합니다 ... 플러그인 개발자 웹 사이트에서 몇 가지 예를 통해 사용하고있는 코드를 자필로 작성했습니다. ** {animateScroll : true, horizontalDragMinWidth : 63} ** 매개 변수를 두 번째 호출로 이동하면 문제가 해결되었습니다. jScrollPane을 한 번만 호출하는 코드를 다시 잡아려고했지만 작동하지 못했습니다. 이 줄을 따라 어떤 제안을 주시면 감사하겠습니다. 그렇지 않으면 나는 그 일을 기쁘게 생각한다 =) – tmc

관련 문제