0
I am developing a page and need to display some text and images randomly on a certain part of the page.
I found it here on the forum (Display text at random) a code that almost does what I need.
Follows the code:
$(document.body).ready(function(){
textos = ['Texto exemplo', 'Texto 2', 'Aleatório', 'Exemplo para o usuário', 'Texto 5'];
$('#textos').text(textos[0]);
setInterval(function() {
var indexTexto = Math.floor(Math.random() * textos.length); //Pegará um número aleatório entre 0 e a quantidade de textos;
$('#textos').text(textos[indexTexto]); //Definirá o texto de acordo com o índice sorteado
},
1000); //1 segundo
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"> </script>
<div id="textos"></div>
But I need that instead of displaying the texts that are inside the code, display some Divs calling them by their respective Ids, which have texts and images.
I have basic knowledge in HTML and no knowledge in Javascript.
If anyone can help me, I’d be grateful.
Your code worked perfectly. Exactly how I need it. Putting your code into practice, I wondered. If a person is reading something inside the Div and in the middle of reading, poof, the text changes or an image appears, the person will be at least dissatisfied with the situation. My question is: Can you add a button with the back option and another button with the pause option? But look, anyway, you helped me immensely. Your code will help me a lot. Thank you so much! Hug.
– michelbtos
Another situation that occurred was that I changed the display time to 1 minute. But the problem is that when you load or reload the page, it takes a minute to display the first Div. Is there any way to change that? Thanks.
– michelbtos