2017-07-31 117 views
7

我用這PullToRefresh插件:pulltorefresh.js - 禁用暫時

https://github.com/BoxFactura/pulltorefresh.js#api

它運作良好,但我有一個彈出我的DIV內嵌滾動頁面上。 問題是,當我想向上滾動(在div中)PullToRefresh被觸發。當彈出窗口打開時,是否可以「刪除」或臨時禁用PullToRefresh?

PullToRefresh.init({ 
    mainElement: 'body', 
    onRefresh: function(){ 
     refreshAll(); 
    } 
}); 

編輯: delete PullToRefresh; //不起作用

EDIT2: https://github.com/BoxFactura/pulltorefresh.js/blob/master/dist/pulltorefresh.js

回答

6

PullToRefresh.init()將與destroy()函數返回一個對象回調:https://github.com/BoxFactura/pulltorefresh.js/blob/master/dist/pulltorefresh.js#L326

var refresher = PullToRefresh.init({ 
    mainElement: 'body', 
    onRefresh: function(){ 
     refreshAll(); 
    } 
}); 

// destroy the PullToRefresh EventListeners when you open your popup 
refresher.destroy() 

還有一個開放的Github問題ab出來改進初始化後破壞這個庫的方法:https://github.com/BoxFactura/pulltorefresh.js/issues/22

0

IMO有兩個合理這樣做的方法。

您可以定義triggerElement並把你覆蓋超出這個triggerElement的:相對弱

PullToRefresh.init({ 
    mainElement: 'body', 
    triggerElement: '#mainContent', 
    onRefresh: refreshAll 
}); 

有點像這個

<body> 
    <div id="containerForOverlays"></div> 
    <div id="mainContent"></div> 
</body> 

這樣的#containerForOverlays裏面一切都不會觸發刷新。


或者如果您的版本已經支持它,您可以使用新掛鉤shouldPullToRefresh()

其中PullToRefresh取決於複選框的例子進行檢查

<label><input id="refresh" type="checkbox"> Pull to Refresh?</label> 

使用它像

PullToRefresh.init({ 
    mainElement: 'body', 
    shouldPullToRefresh: function(){ 
     return document.getElementById('pullToRefresh').checked 
    }, 
    onRefresh: refreshAll 
}); 

當然我不建議您在生產代碼中使用複選框。我只是想展示如何動態地「打開PullToRefresh開啓和關閉」。在這個例子中,取決於要檢查的複選框。

您需要爲您的應用實施正確的shouldPullToRefresh()以確定是否PullToRefresh應該激活或不激活。