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);
}
You clearly are not using the most recent version of Captivate (because you mention click boxes). Please check the full version number under Help, About Captivate.
Too bad, most JS experts have disappeared here since that new version 12 misses a lot of features which did inspire them for real engaging courses. Even the important system variables about timing are no longer exposed:
cpInfoElapsedTimeMS and cpInfoEpochMS
You must be logged in to post a comment.