如何在 4 秒后关闭叠加层?
How can I close an overlay after 4 seconds?
当您加载页面时,我正在使用此代码作为叠加层。现在我可以在触摸时关闭它,但我也想在 4 秒后关闭。我该如何设置?
var widthInitial = parseInt($('#horiz').html());
var heightInitial = parseInt($('#vert').html());
var windowWidth = $(window).width()/100;
var windowHeight = $(window).height()/100;
$('#drag').css('background','hsla('+widthInitial+',85%,'+heightInitial+'%,1)');
$('#drag').bind('mousedown touchstart',function(e) {
e.preventDefault();
var widthInitial = parseInt($('#horiz').html());
var heightInitial = parseInt($('#vert').html());
var xInitial = e.originalEvent.pageX;
var yInitial = e.originalEvent.pageY;
$(document).bind('mousemove touchmove',function(e) {
e.preventDefault();
$('.result').slideUp(300);
$('#instruct').fadeOut();
var movePos = Math.min(Math.max(parseInt(Math.round((e.originalEvent.pageX-xInitial)/windowWidth*3.6)+widthInitial), 0), 360);
var movePosVert = Math.min(Math.max(parseInt(Math.round((e.originalEvent.pageY-yInitial)/windowHeight)+heightInitial), 0), 100);
$('#drag').css('background','hsla('+movePos+',85%,'+movePosVert+'%,1)');
$('.result').css('background','hsla('+(movePos+5)+',85%,'+(movePosVert+15)+'%,1)');
$('#horiz').html(movePos);
$('#vert').html(movePosVert+'%');
if(movePosVert >= 0 && movePosVert < 50) {
$('#drag, .button').css('color','white');
$('.button').css('background','rgba(255,255,255,0.15)');
}
else if(movePosVert > 50 && movePosVert <= 100) {
$('#drag, .button').css('color','black');
$('.button').css('background','rgba(0,0,0,0.15)');
}
HSLvalue = 'hsl('+movePos+',85%,'+movePosVert+'%)';
});
});
你可以这样做:
setTimeout ( function(){
//your code for closing overlay
}, 4000 );
类似于:
window.setTimeout(function(){
alert('Close dialog'); // Or any other code -- so put your code to close your dialog here.
}, 4000); // 4000 = time in milliseconds
当您加载页面时,我正在使用此代码作为叠加层。现在我可以在触摸时关闭它,但我也想在 4 秒后关闭。我该如何设置?
var widthInitial = parseInt($('#horiz').html());
var heightInitial = parseInt($('#vert').html());
var windowWidth = $(window).width()/100;
var windowHeight = $(window).height()/100;
$('#drag').css('background','hsla('+widthInitial+',85%,'+heightInitial+'%,1)');
$('#drag').bind('mousedown touchstart',function(e) {
e.preventDefault();
var widthInitial = parseInt($('#horiz').html());
var heightInitial = parseInt($('#vert').html());
var xInitial = e.originalEvent.pageX;
var yInitial = e.originalEvent.pageY;
$(document).bind('mousemove touchmove',function(e) {
e.preventDefault();
$('.result').slideUp(300);
$('#instruct').fadeOut();
var movePos = Math.min(Math.max(parseInt(Math.round((e.originalEvent.pageX-xInitial)/windowWidth*3.6)+widthInitial), 0), 360);
var movePosVert = Math.min(Math.max(parseInt(Math.round((e.originalEvent.pageY-yInitial)/windowHeight)+heightInitial), 0), 100);
$('#drag').css('background','hsla('+movePos+',85%,'+movePosVert+'%,1)');
$('.result').css('background','hsla('+(movePos+5)+',85%,'+(movePosVert+15)+'%,1)');
$('#horiz').html(movePos);
$('#vert').html(movePosVert+'%');
if(movePosVert >= 0 && movePosVert < 50) {
$('#drag, .button').css('color','white');
$('.button').css('background','rgba(255,255,255,0.15)');
}
else if(movePosVert > 50 && movePosVert <= 100) {
$('#drag, .button').css('color','black');
$('.button').css('background','rgba(0,0,0,0.15)');
}
HSLvalue = 'hsl('+movePos+',85%,'+movePosVert+'%)';
});
});
你可以这样做:
setTimeout ( function(){
//your code for closing overlay
}, 4000 );
类似于:
window.setTimeout(function(){
alert('Close dialog'); // Or any other code -- so put your code to close your dialog here.
}, 4000); // 4000 = time in milliseconds