定时FadeOut无法正常工作

时间:2015-04-13 00:20:30

标签: javascript html fadeout

我一直希望在一段时间后让图像淡出。我查看了Stackoverflow中的相同主题,但我不想工作。

如果有人能快速查看我的代码,我会非常感激吗?

我想淡化的图像是:  

我的代码:

<!DOCTYPE html>
<html lang="en">
<head>

  <!-- Basic Page Needs
  –––––––––––––––––––––––––––––––––––––––––––––––––– -->
  <meta charset="utf-8">
  <title>ACC BIC - Business Industry Description</title>
  <meta name="description" content="">
  <meta name="author" content="">

  <!-- Mobile Specific Metas
  –––––––––––––––––––––––––––––––––––––––––––––––––– -->
  <meta name="viewport" content="width=device-width, initial-scale=1">

  <!-- FONT
  –––––––––––––––––––––––––––––––––––––––––––––––––– -->
  <link href="//fonts.googleapis.com/css?family=Raleway:400,300,600" rel="stylesheet" type="text/css">

  <!-- CSS
  –––––––––––––––––––––––––––––––––––––––––––––––––– -->
  <link rel="stylesheet" href="css/normalize.css">
  <link rel="stylesheet" href="css/skeleton.css">

  <!-- Favicon
  –––––––––––––––––––––––––––––––––––––––––––––––––– -->
  <link rel="icon" type="image/png" href="images/favicon.png">

</head>
<body>

  <!-- Primary Page Layout
  –––––––––––––––––––––––––––––––––––––––––––––––––– -->
  <div class="container">
    <div class="row">
      <div class="twelve columns">
        <!--  Bottom bar navigation -->
        <div class="btn btn-two">
          <span class="btn-two--link"><a href="#.html"></a></span>
          <span class="btn-three--link"><a href="selection-5.html"></a></span>
          <span class="btn-four--link"><a href="index.html"></a></span>
          <img id="myImage" class="email-sent-img" src="images/email-link-sent.png" alt="">
          <script>
          $(window).load(function(){
  setTimeout(function(){ $('#myImage').fadeOut() }, 5000);
});
          </script>
        </div>
        <!--  Background image -->

        <img class="proto-img" src="images/cards-view-selected.png" alt="">
      </div>
    </div>
  </div>

<!-- End Document
  –––––––––––––––––––––––––––––––––––––––––––––––––– -->

</body>
</html>

2 个答案:

答案 0 :(得分:1)

您是否为页面提供了jQuery代码的链接。它看起来不像你有,所以电脑无法理解 $(window).load()事件或$("#myImage").fadeOut()方法。要解决此问题,只需将此行代码添加到页面的head部分 -

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">
</script>

如果您更喜欢使用更高版本的jQuery,可以查看jQuery网站以获取更多信息。 如果仍然无效,请尝试将$("myImage").fadeOut()替换为$("#myImage").fadeTo("slow",0)

希望这有帮助。

答案 1 :(得分:0)

尝试

$(window).on('load', function () {
    setTimeout(function () {
        $("#image").fadeOut("slow", function () { // Instead of Slow you could add 5000 (5s)
            // fade out complete if you need to run another event
        });
    }, 5000); // fade out starts after 5s
});