javascript - Refresh div and randomly change text color -
i have div, pulling random testimonial shortcode in wp.
<div id="testimonial-refresh"><?php echo do_shortcode('[random-testimonial]'); ?></div>
i have script refreshes div every 3 seconds.
<script type="text/javascript"> var auto_refresh = setinterval( function () { $("#testimonial-refresh").load(location.href+" #testimonial-refresh>*",""); }, 3000); </script>
i know how can set 5 colors , have text color change randomly every time div refreshes.
i've set changes color when window reloads. want change color when div reloads.
thank you. i've been searching 2 hours , have not come solution.
update
this takes care of it, it's little glitchy:
<script type="text/javascript"> var colors = ['yellow', 'black', 'orange', 'red', 'blue']; var auto_refresh = setinterval(function () { // load testimonial $("#testimonial-refresh").load(location.href+" #testimonial-refresh>*",""); // change text color randomly var rand = math.floor(math.random() * colors.length); $("#testimonial-refresh").css('color', colors[rand]); }, 3000); </script>
var colors = ['yellow', 'black', 'orange', 'red', 'blue']; var element = $("#testimonial-refresh"); var auto_refresh = setinterval(function () { element.load(location.href+" #testimonial-refresh>*", function() { // load performed -> change text color randomly var rand = math.floor(math.random() * colors.length); element.css('color', colors[rand]); }); }, 3000);
update
if want use script, should work:
var colors = ['yellow', 'black', 'orange', 'red', 'blue']; var auto_refresh = setinterval(function () { // load testimonial $("#testimonial-refresh").fadeout(function() { $(this).load(location.href + "?ts=" + new date().gettime() + " #testimonial-refresh>*", "", function() { // change text color randomly var rand = math.floor(math.random() * colors.length); $("#testimonial-refresh").css('color', colors[rand]); $(this).fadein(); }); }); }, 3000);
Comments
Post a Comment