私のjavascriptの実行を遅らせるのに助けが必要です。(Webページがロードされた直後にjavascriptを実行しないようにしてください)JavaScriptを実行する前に、ロードされる。どうやってやるの?これがスクリプトです。JavaScript - 特定のjavascriptの遅延実行
<script>
var interval = 10000;
var current_index = -1;
var sales_feeds = [];
var showtime = 5000;
<?php $s = get_option('wc_feed_delay_between_popups_appear');
if (!$s) {
$s = 5000;
}
?>
function hide_prev_feed_notify(index)
{
if(sales_feeds.eq(current_index).length > 0)
{
sales_feeds.eq(current_index).animate({bottom: '-90px'}, 500);
}
}
function show_live_feed_notify(index)
{
sales_feeds.eq(index).animate({bottom: '10px'}, 1000);
current_index = index;
}
function show_next_live_notify()
{
if((current_index + 1) >= sales_feeds.length)
{
current_index = -1;
}
//add randomness
current_index = (Math.floor(Math.random() * (sales_feeds.length + 1))) - 1;;
if(window.console)
console.log('will show ' + (current_index+1));
show_live_feed_notify(current_index + 1);
setTimeout(function() { hide_prev_feed_notify(current_index + 1); }, showtime);
}
function stop_live_notify()
{
removeInterval(inverval);
}
function readCookie(name)
{
var nameEQ = escape(name) + "=";
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++)
{
var c = ca[i];
while (c.charAt(0) === ' ') c = c.substring(1, c.length);
if (c.indexOf(nameEQ) === 0) return unescape(c.substring(nameEQ.length, c.length));
}
return null;
}
jQuery(function()
{
jQuery('.wc_feed_close_btn').click(function()
{
var days = 30;
var date = new Date();
date.setTime(date.getTime() + (days *24 *60 *60 *1000));
if(window.console)
console.log(date.toGMTString());
document.cookie = 'wc_feed_closed=true; expires=' + date.toGMTString() + ';';
jQuery('.live-sale-notify').css('display', 'none');
clearInterval(interval);
return false;
});
sales_feeds = jQuery('.live-sale-notify');
show_next_live_notify();
interval = setInterval(show_next_live_notify, (showtime + <?php print $s + 100; ?>));
});
</script>
注:次の実行を延期したいと思います。
function show_live_feed_notify(index)
{
sales_feeds.eq(index).animate({bottom: '10px'}, 1000);
current_index = index;
}
私はそれらのどれも動作するようには思えない
var delay = 10000;
または
var interval = 10000;
を挿入しようとしました。
私もそれがキャッチされない構文エラーで出てきた
setTimeout (function(); 3000);
を試してみました。 よろしくお願いします!
注:私はJS/PHPのコーディングに新たなんだ...
を:それは自動的に
は、スクリプト全体を遅らせ、このようなものでjQueryのコールで最後の2行を置き換えるには、その仕事を行う
setInterval
をさせるのではなく、右の開始時にすべてのものを実行します? –