Random value from list and interval change
I have a few (3-4) value tel number. Refresh to the page shows one random number and inte开发者_如何转开发rvals of 10 seconds, changed to another random number. Preferably with preloader and the effect of a change.
For example
<div class="tel">
<ul>
<li>0 800 900 78 45</li>
<li>0 800 400 47 12</li>
<li>0 870 111 73 43</li>
<li>0 555 500 41 00</li>
</ul>
</div>
You could do something like this:
var numberOfLis = $('.tel ul li').length;
function showRandomLi(){
var randomNum = Math.floor(Math.random() * numberOfLis) +1;
$('.tel ul li').hide();
$('.tel ul li:nth-child('+randomNum+')').show();
}
showRandomLi();
setInterval(showRandomLi, 10000);
Working fiddle: http://jsfiddle.net/HkKwJ/3/
精彩评论