CMS Development

Janette
Teilnehmer/-in

Time interval of JS doesn´t respond correctly

lösung

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);
}

$( document ).ready(function() {

typeEffect();
setInterval (typeEffect(), 5000);
/*setTimeout(function(){
}, delay)*/
});

 

And I add the link about landing:

https://www.inbest.cloud/desarrollo-en-la-nube

 

I commented to you that the title of: "¿QUÉ ES LA NUBE?" it is where I´m attaching this JS code.

 

Also I attach a screenshot where I´m add the script in my template.Script_Encabezado.PNG

If you need know something else plis let know.

 

I remain to your comments.

Thank and Regards

 

0 Upvotes
1 Akzeptierte Lösung
tjoyce
Lösung
Trendsetter/-in | Elite Partner
Trendsetter/-in | Elite Partner

Time interval of JS doesn´t respond correctly

lösung

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.

 

Drop by and say Hi to me on slack.

Lösung in ursprünglichem Beitrag anzeigen

0 Upvotes
2 Antworten
tjoyce
Lösung
Trendsetter/-in | Elite Partner
Trendsetter/-in | Elite Partner

Time interval of JS doesn´t respond correctly

lösung

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.

 

Drop by and say Hi to me on slack.

0 Upvotes
Janette
Teilnehmer/-in

Time interval of JS doesn´t respond correctly

lösung

Thanks @tjoyce 

 

Its work with the first option.

Thanks very much.

Regards