Не работает setInterval внутри jQuery ready в Chrome
Делаю простенький слайдер фотографий на jQuery, не могу сделать авто переключение фото с интервалом.
Использую для этого setInterval: jQuery(document).ready(function(){ /*debug*/ $('.autoPlay').html('autoPlay = '+ window.autoPlay); $('.timePassed').html('timePassed = '+ window.timePassed); $('.timeToChange').html('timeToChange = '+ window.timeToChange ); $('.currentPanel').html('currentPanel = '+ window.currentPanel); setInterval('alert(123)', 1000); console.log("213"); $('img.marquee_panel_photo').each(function(index){ var photoWidth = $('.marquee_container').width(); var photoPosition = index * photoWidth; var cur_src = $(this).attr('src'); var cur_alt = $(this).attr('alt'); console.log($(this).attr('alt')); $('.marquee_photos').append('<img class="marquee_photo" style="left:'+photoPosition+';" src="'+cur_src+'" alt="'+cur_alt+'" width="700" height="350" />'); $('.marquee_photos').css('width', photoPosition + photoWidth); window.totalPanels = index + 1; /*debug*/ $('.totalPanels').html('totalPanels = '+ window.totalPanels) }) $('.marquee_panels .marquee_panel').each(function(index){ $('.marquee_nav').append('<a class="marquee_nav_item"></a>'); // console.log("index "+index); }); $('.marquee_nav a.marquee_nav_item').click(positionPhoto); $('.marquee_panel img').imgpreload(init); }) setTimeout тоже не отрабатывает, если указывать задержку, например 1 сек. Не работает только в Chrome. Версия браузера 28.0.1500.95 m Хотя если я пишу этот setInterval('alert(123)', 1000); внутри самого html файла - отрабатывает нормально. Ошибок в консоли нет. В чём может быть проблема? |
setInterval/setTimeout принимают аргументом не строку, а ссылку на функцию. Например setInterval(function(){ alert('bla') }, 1000);
(на самом деле строку тоже, но просто какое-то недоразумение) |
я пробовал по всякому. И строку и анонимную функцию и обычную, не работает никак
|
<script src="http://code.jquery.com/jquery-latest.min.js"></script> <script> jQuery(document).ready(function(){ /*debug*/ // $('.autoPlay').html('autoPlay = '+ window.autoPlay); // $('.timePassed').html('timePassed = '+ window.timePassed); // $('.timeToChange').html('timeToChange = '+ window.timeToChange ); // $('.currentPanel').html('currentPanel = '+ window.currentPanel); setInterval('alert(123)', 1000); console.log("213"); $('img.marquee_panel_photo').each(function(index){ var photoWidth = $('.marquee_container').width(); var photoPosition = index * photoWidth; var cur_src = $(this).attr('src'); var cur_alt = $(this).attr('alt'); console.log($(this).attr('alt')); $('.marquee_photos').append('<img class="marquee_photo" style="left:'+photoPosition+';" src="'+cur_src+'" alt="'+cur_alt+'" width="700" height="350" />'); $('.marquee_photos').css('width', photoPosition + photoWidth); window.totalPanels = index + 1; /*debug*/ $('.totalPanels').html('totalPanels = '+ window.totalPanels) }) $('.marquee_panels .marquee_panel').each(function(index){ $('.marquee_nav').append('<a class="marquee_nav_item"></a>'); // console.log("index "+index); }); $('.marquee_nav a.marquee_nav_item').click(positionPhoto); // $('.marquee_panel img').imgpreload(init); }) </script> ЧЯДНТ? |
Вложений: 1
Вот архив с проектом, попробуйте запустить marquee.html
|
Цитата:
|
Проблема была в версии jQuery. Я использовал локальную версию 1.6, переключился на 1.10 - всё пошло как надо
|
Часовой пояс GMT +3, время: 16:53. |