jquery - Timing in JavaScript: Finding a way to make setInterval alternate time -
i building web page class project, , specifically, "about us" page iterates through pictures , descriptions of team members. on view, have this:
setinterval(function() {   $("#about-img").attr('src', img_src[i]);   $("#name").html(names[i]);   $("#description").html(descriptions[i]);   = (i + 1) % img_src.length; }, 8000); this iterates, however, descriptions longer others. there way wait longer, longer description is? simple be
waits(descriptions[i].length * 50); right in setinterval function, javascript has no way of doing that. can do? settimeout asynchronous, , cannot influence second parameter of setinterval scope of first.
use settimeout instead of interval
function changemessage () {     $("#about-img").attr('src', img_src[i]);     $("#name").html(names[i]);     $("#description").html(descriptions[i]);     = (i + 1) % img_src.length;     window.settimeout(changemessage, descriptions[i].length * 50); } 
Comments
Post a Comment