I am creating a landing page in which I am adding JS code with a function of typeEffect that function if I recognize it and execute it correctly. But when I add an interval for that function to execute it every so often, it ignores the time interval. I have reviewed the JS code with the company development team and in theory it is correct. I do not know if I have to see something with HubSpot. Can you help me review this issue, please? I add the JS code that I am using:
function typeEffect() {
var speed = 75; var delay = $('h2').text().length * speed + speed;
var text = $('h2').text(); $('h2').html('');
var i = 0; var timer = setInterval(function() { if (i < text.length) { $('h2').append(text.charAt(i)); i++; } else { clearInterval(timer); } }, speed); }
You're close. There's 2 ways to call setInterval. (1) is to pass a function object reference [in quotes], and (2) is to call an anonymous function that calls your main function
1.
setInterval("typeEffect()", 1000)
2.
setInterval(function(){
typeEffect();
}, 1000)
If this answer helped, please, mark as solved 😄
tim@belch.io | forms.belch.io | Design your own Beautiful HubSpot Forms; No coding necessary.
You're close. There's 2 ways to call setInterval. (1) is to pass a function object reference [in quotes], and (2) is to call an anonymous function that calls your main function
1.
setInterval("typeEffect()", 1000)
2.
setInterval(function(){
typeEffect();
}, 1000)
If this answer helped, please, mark as solved 😄
tim@belch.io | forms.belch.io | Design your own Beautiful HubSpot Forms; No coding necessary.