добавление переменной внутри .delay
Есть код который проявляет текст с определённой задержкой.
<!DOCTYPE html> <html> <head> <script src="http://code.jquery.com/jquery-latest.js"></script> </head> <body> <text id="1">I</text> <text id="2">am</text> <text id="3">happy</text> <text id="4">to</text> <text id="5">join</text> <text id="6">with</text> <text id="7">you</text> <text id="8">today</text> <text id="9">in</text> <text id="10">what</text> <text id="11">will</text> <text id="12">go</text> <text id="13">down</text> <text id="14">in</text> <text id="15">history</text> <text id="16">as</text> <text id="17">the</text> <text id="18">greatest</text> <text id="19">demonstration</text> <text id="20">for</text> <text id="21">freedom</text> <text id="22">in</text> <text id="23">the</text> <text id="24">history</text> <text id="25">of</text> <text id="26">our</text> <text id="27">nation.</text> <script> // Список слов var arrText = [ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27" ]; var arrTime = [ "100", "150", "200", "250", "300", "350", "400", "450", "500", "100", "110", "120", "130", "140", "150", "160", "170", "180", "199", "210", "211", "224", "23", "24", "25", "26", "270" ]; var time = jQuery.each(arrTime, function() { $(this); }); jQuery.each(arrText, function(i) { $("#" + this).css("display","none").delay(100*i).fadeOut('fast', function() { $(this).fadeIn('slow'); }); }); </script> </body> </html> Нужно заменить интервал 100 {.delay(100*i)} на значение в массиве arrTime. Я делаю своего рода интерактивную книжку при прослушивании аудио будет появляться текст. |
Tora,
:write: <!DOCTYPE html> <html> <head> <script src="http://code.jquery.com/jquery-latest.js"></script> </head> <body> <text id="1">I</text> <text id="2">am</text> <text id="3">happy</text> <text id="4">to</text> <text id="5">join</text> <text id="6">with</text> <text id="7">you</text> <text id="8">today</text> <text id="9">in</text> <text id="10">what</text> <text id="11">will</text> <text id="12">go</text> <text id="13">down</text> <text id="14">in</text> <text id="15">history</text> <text id="16">as</text> <text id="17">the</text> <text id="18">greatest</text> <text id="19">demonstration</text> <text id="20">for</text> <text id="21">freedom</text> <text id="22">in</text> <text id="23">the</text> <text id="24">history</text> <text id="25">of</text> <text id="26">our</text> <text id="27">nation.</text> <script> // Список слов var arrText = [ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27" ]; var arrTime = [ "100", "150", "200", "250", "300", "350", "400", "450", "500", "100", "110", "120", "130", "140", "150", "160", "170", "180", "199", "210", "211", "224", "23", "24", "25", "26", "270" ]; var time = jQuery.each(arrTime, function() { $(this); }); function pause(k) { var t = 0; for (var i=0; i<=k; i++) {t+=+arrTime[i]} return t } jQuery.each(arrText, function(i) { $("#" + this).css("display","none").delay(pause(i)).fadeOut('fast', function() { $(this).fadeIn('slow'); }); }); </script> </body> </html> |
Часовой пояс GMT +3, время: 03:53. |