用js写一个判读,例如:一个层,第一次是10秒后弹出,关闭以后,20秒再次弹出,关闭以后,40秒以后再次弹出。然后就不弹出了。
var firstShow = 10000;
var secondShow = 20000;
var threeShow = 400000;
setTimeout(openMpM, firstShow);
function openMpM() {
$("#swtCenter2").fadeIn(1000);
}
var clearAfter = setTimeout(openMpM, secondShow);
var clearAfter1 = setTimeout(openMpM, threeShow);
function closeM() {
$("#swtCenter2").fadeOut(1000);
setTimeout(openMpM, 50000);
}
直接没有思路,怎么让他三次以后就不弹了呢,希望详细写一下。
代言2017-06-12 09:34:02
function first(){
alert('第一次');
setTimeout(second,20000);
}
function second(){
alert('第二次');
setTimeout(third,40000);
}
function third(){
alert('第三次')
}
setTimeout(first,10000);
这样不知道能不能行
var firstShow=1000;
var secondShow=5000;
var threeShow=10000;
var n=0;
setTimeout(openMpM,1000);
function openMpM() {
$("#swtCenter2").fadeIn(1000);
$("#swtCenter2").fadeOut(1000);
n++;
switch (n){
case 1:
setTimeout(openMpM,secondShow);
break;
case 2:
setTimeout(openMpM,threeShow);
break;
}
}
显示隐藏条件 你自己加
迷茫2017-06-12 09:34:02
<p id="box"></p>
<button id="btn">hide</button>
<script>
var times = [2000, 4000, 6000];
function State(times) {
var self = this;
this.times = times
this.oBox = document.getElementById('box');
this.btn = document.getElementById('btn');
this.i = 0;
this.btn.onclick = function() {
self.change()
}
}
State.prototype.show = function() {
var self = this;
setTimeout(function() {
self.oBox.style.display = "block";
}, this.times[this.i++])
}
State.prototype.change = function(time) {
if(this.i == this.times.length) {
alert('没有数据了');
return;
}
this.oBox.style.display = 'none';
this.time = time
this.show();
}
var s = new State(times);
s.show();
</script>
你参考下这个,关闭的时候是手动点击关闭的
PHP中文网2017-06-12 09:34:02
简单地实现了一下,不知道有没有满足你的需求
var timer,num=4;
$('关闭').on('click',function(){
$("#swtCenter2").fadeOut();
clearInterval(timer);
alertTime();
});
function alertTime(){
num--;
if(num<=0){
clearInterval(timer);
return false;
}
timer=setInterval(function(){
$("#swtCenter2").fadeIn();
},10000);
}
alertTime();
搞错时间了,稍微改了一下,应该就是这样
var timer,num=-1;
$('关闭').on('click',function(){
$("#swtCenter2").fadeOut(0);
clearInterval(timer);
alertTime();
});
function alertTime(){
num++;
var idx=num;
idx=!idx?0.5:idx;
if(num>2){
clearInterval(timer);
return false;
}
timer=setInterval(function(){
$("#swtCenter2").fadeIn(0);
},10000*2*idx);
}
alertTime();