2012-06-07 4 views
1

페이지의 시작과 끝에서 슬라이드가 멈추도록하고 싶습니다.
나는 방지하기 위해 의미 페이지 슬쩍 바로과의 시작 페이지 슬쩍 왼쪽 에 :Sencha Touch 2 회전 목마 : 시작/끝 페이지의 스 와이프

Carousel

어떤 설정이 아니면 그것을 구현하는 다른 방법은 없을까요?

미리 감사드립니다.

+1

확인이 밖으로 LockableCarousel 클래스 : HTTP : //stackoverflow.com/a/9365898/862474 – tarikakyol

답변

1

기본적으로 ST2의 carousel 구성 요소는이 구성을 갖습니다. 따라서 을 수행 할 필요가 없습니다.

Sencha 웹 사이트의 this 예제를 살펴보십시오. 마지막 항목에 도달하면 오른쪽으로 넘기는 것을 방지하고 첫 번째 항목에있을 때 왼쪽으로 넘기는 것을 방지합니다.

Ext.create('Ext.Carousel', { 
    fullscreen: true, 

    defaults: { 
     styleHtmlContent: true 
    }, 

    items: [ 
     { 
      html : 'Item 1', 
      style: 'background-color: #5E99CC' 
     }, 
     { 
      html : 'Item 2', 
      style: 'background-color: #759E60' 
     }, 
     { 
      html : 'Item 3' 
     } 
    ] 
}); 
+0

답변 해 주셔서 감사합니다. 어쩌면 내가 원하는 것을 정확히 설명하지 않았을 수도 있습니다. 마지막 카드의 경우 오른쪽으로 스 와이프되지만 자동으로 스 와이프하여 스 와이프를 방지합니다. 승인. 하지만 나는 이것을 원하지 않는다. 나는 심지어 오른쪽으로 스 와이프하고 다시 돌아가고 싶지 않습니다. 나는 마지막 카드를 스 와이프하여 '잠금'하고 싶습니다. 위의 예에서 'Item 1'카드에서 왼쪽으로 스 와이프하면 흰색 배경을보고 싶지 않습니다. 내가 원하는 걸 설명 할 수 있을까? 미리 감사드립니다. – Natasha

1

당신은 당신의 자신의 회전 목마를 만든 다음 다음 onDrag 이벤트를 재정의 할 수 있습니다하면 코드 형태의 Ext.carousel.Carousel에게

Ext.define('Ext.carousel.Custom', { 
    extend: 'Ext.carousel.Carousel', 

    onDrag: function(e) { 
     if (!this.isDragging) { 
      return; 
     } 

     var startOffset = this.dragStartOffset, 
      direction = this.getDirection(), 
      delta = direction === 'horizontal' ? e.deltaX : e.deltaY, 
      lastOffset = this.offset, 
      flickStartTime = this.flickStartTime, 
      dragDirection = this.dragDirection, 
      now = Ext.Date.now(), 
      currentActiveIndex = this.getActiveIndex(), 
      maxIndex = this.getMaxItemIndex(), 
      lastDragDirection = dragDirection, 
      offset; 

     if ((currentActiveIndex === 0 && delta > 0) || (currentActiveIndex === maxIndex && delta < 0)) { 
      delta *= 0.5; 
     } 

     offset = startOffset + delta; 

     if (offset > lastOffset) { 
      dragDirection = 1; 
     } 
     else if (offset < lastOffset) { 
      dragDirection = -1; 
     } 

     if (dragDirection !== lastDragDirection || (now - flickStartTime) > 300) { 
      this.flickStartOffset = lastOffset; 
      this.flickStartTime = now; 
     } 

     this.dragDirection = dragDirection; 

     // now that we have the dragDirection, we should use that to check if there 
     // is an item to drag to 
     if ((dragDirection == 1 && currentActiveIndex == 0) || (dragDirection == -1 && currentActiveIndex == maxIndex)) { 
      return; 
     } 

     this.setOffset(offset); 
    } 
}); 

참조입니다 : = Link