Need JavaScript help! Force tap and hold on click boxes

I need JavaScript code to require tap and hold (of at least 800 milliseconds) on select click boxes in a Captivate project.  If the learner holds the finger or mouse on the click box, only then will it proceed to the next slide.

I have used Chat GPT to write the core code, but I can not get it to work correctly in the CPTX file.  Any help with the code will be greatly appreciated!  –Rochelle Flynn

let isTouchDevice = cpAPIInterface.isTouchDevice();

const clickBox = document.getElementById(‘myClickBox’);

if (isTouchDevice) {

clickBox.addEventListener(‘touchstart’, handleTouchStart);

clickBox.addEventListener(‘touchend’, handleTouchEnd);

} else {

clickBox.addEventListener(‘mousedown’, handleMouseDown);

clickBox.addEventListener(‘mouseup’, handleMouseUp);

}

let timer;

function handleTouchStart() {

timer = setTimeout(function () {

cpAPIInterface.nextSlide(); // Navigate to the next slide

}, 800); // Adjust the duration as needed

}

function handleTouchEnd() {

clearTimeout(timer);

}

function handleMouseDown() {

timer = setTimeout(function () {

cpAPIInterface.nextSlide(); // Navigate to the next slide

}, 800); // Adjust the duration as needed

}

function handleMouseUp() {

clearTimeout(timer);

}

The post Need JavaScript help! Force tap and hold on click boxes appeared first on eLearning.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *