Javascript.RU

Создать новую тему Ответ
 
Опции темы Искать в теме
  #1 (permalink)  
Старый 27.07.2013, 13:42
Новичок на форуме
Отправить личное сообщение для Tora Посмотреть профиль Найти все сообщения от Tora
 
Регистрация: 24.03.2011
Сообщений: 2

добавление переменной внутри .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.
Я делаю своего рода интерактивную книжку при прослушивании аудио будет появляться текст.
Ответить с цитированием
  #2 (permalink)  
Старый 27.07.2013, 13:58
Аватар для рони
Профессор
Отправить личное сообщение для рони Посмотреть профиль Найти все сообщения от рони
 
Регистрация: 27.05.2010
Сообщений: 33,103

Tora,

<!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>
Ответить с цитированием
Ответ



Опции темы Искать в теме
Искать в теме:

Расширенный поиск


Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Получение значения переменной внутри обработчика события jQuery Mbenga Общие вопросы Javascript 2 01.07.2013 10:57
Вызов локальной функций внутри переменной gibigate Общие вопросы Javascript 1 20.03.2013 14:47
Как обратиться к переменной внутри объекта, в произвольной функцию через его метод platedz Элементы интерфейса 15 25.08.2012 00:03
изменение значения глобальной переменной внутри функции mgmarket Серверные языки и технологии 14 13.09.2011 00:56
Добавление значения переменной в textarea IamSmorodin Общие вопросы Javascript 13 09.04.2009 10:59