我们点击链接<a

时间:2018-03-19 18:25:05

标签: javascript jquery css

="" I have a loading icon in CSS, when someone clicks on a link the problem is in the mobile version I have a slide menu that open with one tag, or link, and the CSS icon is showing and never disappear.

I need to hide the CSS icon after 3 sec, this is my code.

$('a').click(function(){
     $('.loadingDiv').fadeIn('slow', function(){
               $('.loadingDiv').delay(3000).fadeOut(); 
            });
   $('<div class="loadingDiv mobileShow"></div>').prependTo(document.body); 
});
.loadingDiv {
    position: fixed;
    left: 45%;
    top: 30%;
    width: 100%;
    height: 100%;
    z-index: 9999;
    opacity: .5;
    width: 40px;
  height: 40px;
  background-color: #333;

  width: 40px;
  height: 40px;
  background-color: #333;

  margin: 100px auto;
  -webkit-animation: sk-rotateplane 1.2s infinite ease-in-out;
  animation: sk-rotateplane 1.2s infinite ease-in-out;
}

@-webkit-keyframes sk-rotateplane {
  0% { -webkit-transform: perspective(120px) }
  50% { -webkit-transform: perspective(120px) rotateY(180deg) }
  100% { -webkit-transform: perspective(120px) rotateY(180deg)  rotateX(180deg) }
}

@keyframes sk-rotateplane {
  0% { 
    transform: perspective(120px) rotateX(0deg) rotateY(0deg);
    -webkit-transform: perspective(120px) rotateX(0deg) rotateY(0deg) 
  } 50% { 
    transform: perspective(120px) rotateX(-180.1deg) rotateY(0deg);
    -webkit-transform: perspective(120px) rotateX(-180.1deg) rotateY(0deg) 
  } 100% { 
    transform: perspective(120px) rotateX(-180deg) rotateY(-179.9deg);
    -webkit-transform: perspective(120px) rotateX(-180deg) rotateY(-179.9deg);
  }
}

But is not working, any help will be great, because the

1 个答案:

答案 0 :(得分:3)

不要忘记setTimeout

你可以简单地说:

setTimeout(function () {
  ... do the fading out here ...
}, 3000);

我总是比jQuery更喜欢vanila-js解决方案。 ;)

干杯!