javascript - Fade element out and fade in data from Array - jQuery -
i have 4 div
items on page, i'm trying inner html of these items fade out randomly, take row array , fade in - in place, make sense?
// items repopulate faded out info var testimonialsarray = [ "<div class='change'><h1>box 5</h1><p>lorem ipsum</p></div>", "<div class='change'><h1>box 6</h1><p>lorem ipsum</p></div>", "<div class='change'><h1>box 7</h1><p>lorem ipsum</p></div>", "<div class='change'><h1>box 8</h1><p>lorem ipsum</p></div>", "<div class='change'><h1>box 9</h1><p>lorem ipsum</p></div>" ]; // find random div , fade out var order = math.floor((math.random()* $('.change').length )+1); $('.box').eq(order).find('.change').fadeout(); .......fade in new data array row
based on think wanted do:
var order = math.floor((math.random()* $('.change').length )); $('.box').eq(order).find('.change').fadeout(function(){ $(this).html(testimonialsarray[math.floor((math.random()* testimonialsarray.length))]).fadein(); });
jsfiddle: http://jsfiddle.net/crn7dysu/4/
Comments
Post a Comment