I'm trying to call the value in a Metabox custom field (number) into this Javascript I'm using on a page layout in Beaver Builder.
In "Count1", I want to replace the target number (marked with *) in this code with the value of the metabox field.
Is there any way to do this?
document.addEventListener("DOMContentLoaded", () => {
function counter(id, start, end, duration) {
let obj = document.getElementById(id),
current = start,
range = end - start,
increment = end > start ? 1 : -1,
step = Math.abs(Math.floor(duration / range)),
timer = setInterval(() => {
current += increment;
obj.textContent = current;
if (current == end) {
clearInterval(timer);
}
}, step);
}
counter("count1", 50, *25, 2000);
});
Thank you very much!