Jquery 如何在4秒后关闭覆盖?

Jquery 如何在4秒后关闭覆盖?,jquery,overlay,Jquery,Overlay,当你加载页面时,我正在使用这个代码进行覆盖。现在我可以在触摸时关闭它,但我也想在4秒钟后关闭它。我怎么设置这个 var widthInitial = parseInt($('#horiz').html()); var heightInitial = parseInt($('#vert').html()); var windowWidth = $(window).width()/100; var windowHeight = $(window).height()/100; $('#drag').c

当你加载页面时,我正在使用这个代码进行覆盖。现在我可以在触摸时关闭它,但我也想在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+'%)';
    });

});
var-widthInitial=parseInt($('#horiz').html();
var heightInitial=parseInt($('#vert').html());
var windowWidth=$(window).width()/100;
var windowHeight=$(window).height()/100;
$(“#拖动”).css('background','hsla('widthInitial+',85%,'heightInitial+',1');
$(“#拖动”).bind('mousedown touchstart',函数(e){
e、 预防默认值();
var widthInitial=parseInt($('#horiz').html();
var heightInitial=parseInt($('#vert').html());
var xInitial=e.originalEvent.pageX;
var yInitial=e.originalEvent.pageY;
$(document).bind('mousemove touchmove',函数(e){
e、 预防默认值();
$('.result').slideUp(300);
$(“#指令”).fadeOut();
var movePos=Math.min(Math.max(parseInt(Math.round)((e.originalEvent.pageX xInitial)/windowWidth*3.6)+widthsinitial),0),360);
var movePosVert=Math.min(Math.max(parseInt(Math.round((e.originalEvent.pageY yInitial)/windowHeight)+heightInitial),0),100);
$('拖动').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){
$('#拖动,.button').css('color','white');
$('.button').css('background','rgba(255255,0.15)');
}
否则,如果(movePosVert>50&&movePosVert您可以执行以下操作:

setTimeout ( function(){
    //your code for closing overlay
}, 4000 );

类似于:

window.setTimeout(函数(){
alert('Close dialog');//或任何其他代码——因此请在此处输入代码以关闭对话框。
},4000);//4000=以毫秒为单位的时间
谷歌搜索“javascript超时”将是一个很好的开始。
$(“#拖动”).hide();
或fadeOut();