I have this piece of jQuery. It shows randomly some phrases.
The phrases are shown with an interval:
window.setInterval(getMessage, 350);
I want to decrease the 350
to 1
over a period of 10 seconds after a click on the body
.
I have this code. How can I get the 350
to 1
after the click on the body
?
Thank you!
$(document).ready(function () {
// Elements to loop through
var elem = $('.message');
// Start at 0
z = 0;
function getMessage() {
// Loop through elements
$(elem).each(function (index) {
if (z == index) {
// Show active element
$(this).show();
} else if (z == $(elem).length) {
// Show message
$(this).show();
// Reset i lst number is reached
z = 0;
} else {
// Hide all non active elements
$(this).hide();
}
});
z++;
}
// Run once the first time
getMessage();
// Repeat
window.setInterval(getMessage, 350);
});
$('body').click(function () {
$('body').addClass('run');
});