2011-08-10 87 views
2

我試圖阻止瀏覽器窗口滾動,如果我已經達到我的jscrollpane div的頂部或底部。 Tinyscrollbar這樣做。jQuery,jscrollpane - 防止窗口滾動時達到div的末端

jscrollpane我可以檢測分度,這樣的事情滾動:

var jsp = $(".scroll-pane").data('jsp'); // getting hold of the api 
jsp = $("#" + e.attr('id') + " > .feed-items").bind(
    'jsp-scroll-y', function(e, scrollPositionY, isAtTop, isAtBottom) { 
     // reached bottom 
     if (jsp.getPercentScrolledY() == 1) { 
     } else { 
      // ... 
     } 
    }) 

我嘗試使用e.preventDefault()並沒有奏效。我嘗試了魔術盒中的所有內容,從返回false到停止傳播。什麼都沒有有這個很好的黑客:

$("body").css("overflow", "hidden") 
     .css('margin-left', "-" + __scrollbarWidth + "px"); 

但我不想使用它,因爲它不完美。

任何想法?

+0

'返回false;據我所知,應該工作。 – sasidhar

+0

它不起作用。 =/ –

+0

我也想知道 –

回答

2
  • 必須例如類測試添加到div
  • 添加一些javascript:

    $(document).on('mousewheel', '.test', 
         function (e) { 
         var delta = e.originalEvent.wheelDelta; 
         this.scrollTop += (delta < 0 ? 1 : -1) * 30; 
         e.preventDefault(); 
    }); 
    

其垂直滾動。如果你想要做同樣的水平滾動讓我知道

+0

工作得很好。謝啦! –

2

我不知道爲什麼它的工作,但是當你的鼠標滾輪到達底部或頂部的停止滾動;)

/* Stop scrolling */ 
$('#cnct_form').bind('jsp-scroll-y',function(event, isScrollable) { 
     console.log('asd'); 
}).jScrollPane(); 

$('#cnct_form').mousewheel(function(event) { 
    event.preventDefault(); 
});