如何在4秒后关闭叠加?

时间:2015-01-27 15:50:40

标签: jquery overlay

我在加载页面时使用此代码进行叠加。现在我可以在触摸时关闭它,但我想在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+'%)';
    });

});

2 个答案:

答案 0 :(得分:0)

你可以这样做:

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

答案 1 :(得分:0)

类似的东西:

window.setTimeout(function(){
  alert('Close dialog'); // Or any other code -- so put your code to close your dialog here.
}, 4000); // 4000 = time in milliseconds
相关问题