1

我很难弄清楚如何在移动到另一个滑块之前等待或延迟滑块约 1 秒。下面是JavaScript。我没有分享 html 代码,因为它太长而且我的问题看起来很乱。我希望你们中的一些人有想法。我真的很感谢你的帮助。

js代码

var swiper = new Swiper('.swiper-container', {
 
    autoHeight: true, //enable auto height    
    mousewheelControl: false,
    touchRatio: 0,
    allowTouchMove: false,
    shortSwipes: false,
    speed:2000,
    navigation: {
        nextEl: '.swiper-button-next',
    },

});
4

1 回答 1

0

我很难弄清楚如何等待或延迟 [...] 大约 1 秒

如果您希望延迟脚本执行,您需要setTimeout.


setTimeout 的剖析:

setTimeout( [CALLBACK FUNCTION], [TIME DELAY] );

工作示例:

const myButton = document.getElementsByTagName('button')[0];

const clickButton = () => {

  setTimeout(() => {
  
    let myParagraph = document.createElement('p');
    myParagraph.textContent = 'You clicked the button.';
    document.body.appendChild(myParagraph);

  }, 1000);

}

myButton.addEventListener('click', clickButton, false);
<button type="button">Click Me</button>
<p>A second after you click the button above, more text will appear...</p>

于 2020-10-20T10:22:33.833 回答