【发布时间】:2010-02-18 21:36:08
【问题描述】:
您好,我的网站有一个演示:treethink.treethink.net/backup
我在计时器的右侧有收回新闻代码,当您单击导航项目时,我让代码收回,但我需要结束计时器以使其保持收回。然后,当您单击关闭按钮时,我需要再次启动计时器。
这是我的 jQuery:
/* News Ticker */
/* Initially hide all news items */
$('#ticker1').hide();
$('#ticker2').hide();
$('#ticker3').hide();
var randomNum = Math.floor(Math.random()*3); /* Pick random number */
$("#ticker").oneTime(2000,function(i) { /* Do the first pull out once */
$('div#ticker div:eq(' + randomNum + ')').show(); /* Select div with random number */
$("#ticker").animate({right: "0"}, {duration: 800 }); /* Pull out ticker with random div */
});
$("#ticker").oneTime(15000,function(i) { /* Do the first retract once */
$("#ticker").animate({right: "-450"}, {duration: 800}); /* Retract ticker */
$("#ticker").oneTime(1000,function(i) { /* Afterwards */
$('div#ticker div:eq(' + (randomNum) + ')').hide(); /* Hide that div */
});
});
$("#ticker").everyTime(16500,function(i) { /* Everytime timer gets to certain point */
/* Show next div */
randomNum = (randomNum+1)%3;
$('div#ticker div:eq(' + (randomNum) + ')').show();
$("#ticker").animate({right: "0"}, {duration: 800}); /* Pull out right away */
$("#ticker").oneTime(15000,function(i) { /* Afterwards */
$("#ticker").animate({right: "-450"}, {duration: 800});/* Retract ticker */
});
$("#ticker").oneTime(16000,function(i) { /* Afterwards */
/* Hide all divs */
$('#ticker1').hide();
$('#ticker2').hide();
$('#ticker3').hide();
});
});
/* Nav Items */
$("#nav li").click(function() { /* On click */
$("#ticker").animate({right: "-450"}, {duration: 800});/* Retract ticker */
$("#content").stop()
.animate({
top: '0'
}, 750);
$("#content").oneTime(750,function(i) {
$("#content-footer-top").stop()
.animate({
bottom: '42px'
}, 250);
$("#content-footer").stop()
.animate({
bottom: '0'
}, 250);
});
});
$("li#close").click(function() { /* On click */
$("#content").oneTime(1000,function(i) {
$('#content div.content-page').hide();
});
$("#content").oneTime(250,function(i) {
$("#content").stop()
.animate({
top: '-100%'
}, 750);
});
$("#content-footer-top").stop()
.animate({
bottom: '-46px'
}, 250);
$("#content-footer").stop()
.animate({
bottom: '-88px'
}, 250);
});
$('#content div.content-page').hide();
$("#nav li#services").click(function() {
$('#content #services').show();
});
$("#nav li#portfolio").click(function() {
$('#content #portfolio').show();
});
$("#nav li#contact").click(function() {
$('#content #contact').show();
});
【问题讨论】:
-
我可以将新闻自动收录器放在一个函数中,在页面加载时启动该函数,然后在单击导航项时将其终止,然后在关闭时重新启动?我还想过在单击导航项时收回 div 并隐藏它,然后显示它,然后在单击关闭时将其提取。
-
好的,我现在正在使用隐藏方法,但计时器仍在后台运行,这意味着当 div 关闭时它不会重新开始循环,而是可能需要整个时间再次缩回,或者它可能会在半秒后缩回,具体取决于它在循环中的位置。