简体   繁体   English

实现轮播箭头无法在移动设备上使用

[英]Materialize carousel Arrows Not Working On Mobile

I have a full-width carousel using materialize with some arrows signaling next and previous carousel elements. 我有一个使用实体化的全宽轮播,带有一些箭头,指示下一个和上一个轮播元素。 Works great on desktop but they are not working on mobile. 在台式机上运行良好,但在移动设备上无法运行。 I have been researching it and supposedly there is a bug (no surprise) with this element that they have not covered up. 我一直在研究它,并且据推测,这个元素存在一个错误(不足为奇),而他们没有掩盖。 I was wondering if anyone has ran into this similar problem and knew a way around it? 我想知道是否有人遇到过类似的问题并知道解决方法? The following code worked for one individual just not for me: 以下代码仅对我一个人有效:

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);
}

On mobile it can be dragged just not able to be initiated by clicking the buttons. 在移动设备上,可以通过单击按钮将其拖动以使其无法启动。

You need to replace that code snippet in materialize.js (0.100.2) 您需要在materialize.js (0.100.2) 替换该代码段

host the materialize files locally so you can customize it. 在本地托管实现文件,以便您可以对其进行自定义。

search for this implementation in it. 在其中搜索此实现。

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);
}

replace the above code ^ with the code given below: 将上面的代码^替换为下面给出的代码:

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);
}

Everything should now be working as expected. 现在一切都应按预期工作。

Reference & thanks to ddiaz914 for the fix. 参考并感谢ddiaz914的修复。 github issue #5052 github问题#5052

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM