[英]Materialize carousel Arrows Not Working On Mobile
我有一個使用實體化的全寬輪播,帶有一些箭頭,指示下一個和上一個輪播元素。 在台式機上運行良好,但在移動設備上無法運行。 我一直在研究它,並且據推測,這個元素存在一個錯誤(不足為奇),而他們沒有掩蓋。 我想知道是否有人遇到過類似的問題並知道解決方法? 以下代碼僅對我一個人有效:
function setupEvents() {
if (typeof window.ontouchstart !== 'undefined') {
view.on('touchstart.carousel', tap);
view.on('touchmove.carousel', drag);
view.on('touchend.carousel', release);
}
view.on('mousedown.carousel', tap);
view.on('mousemove.carousel', drag);
view.on('mouseup.carousel', release);
view.on('mouseleave.carousel', release);
view.on('click.carousel', click);
}
在移動設備上,可以通過單擊按鈕將其拖動以使其無法啟動。
您需要在materialize.js (0.100.2)
替換該代碼段
在本地托管實現文件,以便您可以對其進行自定義。
在其中搜索此實現。
function setupEvents() {
if (typeof window.ontouchstart !== 'undefined') {
view.on('touchstart.carousel', tap);
view.on('touchmove.carousel', drag);
view.on('touchend.carousel', release);
}
view.on('mousedown.carousel', tap);
view.on('mousemove.carousel', drag);
view.on('mouseup.carousel', release);
view.on('mouseleave.carousel', release);
view.on('click.carousel', click);
}
將上面的代碼^替換為下面給出的代碼:
function setupEvents() {
if (typeof window.ontouchstart !== 'undefined') {
view[0].addEventListener('touchstart', tap);
view[0].addEventListener('touchmove', drag);
view[0].addEventListener('touchend', release);
}
view[0].addEventListener('mousedown', tap);
view[0].addEventListener('mousemove', drag);
view[0].addEventListener('mouseup', release);
view[0].addEventListener('mouseleave', release);
view[0].addEventListener('click', click);
}
現在一切都應按預期工作。
參考並感謝ddiaz914
的修復。 github問題#5052
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.