【问题标题】:How to make the splash page div fade after being clicked如何使启动页面div在被点击后淡出
【发布时间】:2016-07-13 02:22:24
【问题描述】:

这是我的第一篇文章 - 无论如何 - 我引用了这个原始问题 Welcome screen before website loads (Click to enter) [Splash Screen]

按照第二个答案的说明创建了两个单独的 div 后,我需要帮助来了解如何在用户单击启动画面时/之后使用 javascript 更改启动画面 div 的可见性。

我对代码有非常基本的了解,但我在掌握概念方面很不错。到目前为止,这是我所得到的:

<!Splash html>
<html>
<head>
<meta charset="utf-8" />
<style>
html, body {
margin: 0;
padding: 0
}

div#splash {
max-width: 100%;
height: 100%;
background-image: url("brightsplash.jpg");
background-repeat: no-repeat;
background-size: cover;
}

div#post-splash {
display: none;}
</style>
<div id="splash">


</div>
<div id="post-splash"></div>
<h1>Taylor Forrest</h1>
<h2>photography</h2>
<h2>About</h2>
<h2>Portfolio</h2>
<h2>Contact</h2>

</html>

【问题讨论】:

  • &lt;!Splash html&gt;... 什么? head 标签和body 标签的结束在哪里?

标签: javascript html css


【解决方案1】:

带有隐藏复选框的纯 CSS(无 javascript)替代方案:

html {
  width: 100%;
  height: 100%;  
  background: lavender;
  text-align: center;
  font-family: arial, sans-serif;
}

input { 
  display: none;
}

#target { 
  opacity: 0;
  background-color: rosybrown;
  background: url('http://i.imgur.com/P9L9jzT.jpg');
  background-repeat: no-repeat;
  background-size: 100% 100%;
  background-position: center;
  position: fixed;
  height: 100%;
  width: 100%;  
  top: 0;
  left: 0;
  z-index: -1;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-transition: all 2s; /* Safari */
  transition: all 2s;
}

#click:checked ~ label > #target {
  opacity: 1;
  z-index: 200;
  cursor: pointer;  
  pointer-events: auto;
}

#replay {
  color: crimson;
  position: absolute;
  left: 50%;
  -webkit-transform: translateX(-50%);
  -ms-transform: translateX(-50%);
  transform: translateX(-50%);
  bottom: 20px;
  cursor: pointer;
}

#warning {
  color: white;
  position: fixed;
  top: 50%;
  -webkit-transform: translateY(-50%);
  -ms-transform: translateY(-50%);
  transform: translateY(-50%);
  left: 0;
  right: 0;
  margin: auto;
}
<input type="checkbox" id="click" checked/>

<label for="click">
<div id=target><h1 id=warning>WELCOME</h1></div> 
<span id=replay><small>-replay-</small></span>
</label>

<p>page content</p>

【讨论】:

  • 这太棒了!感谢您对实际点击部分的帮助!
【解决方案2】:

你的代码很乱——你缺少标签,错放了一些内容等等。我建议你更多地了解h html和css,并使用带有语法高亮的适当IDE。无论如何,这里的代码可以满足您的期望。这还远远不够完美。

<html>

<head>
    <meta charset="utf-8" />
    <style>
    html,
    body {
        margin: 0;
        padding: 0
    }

    #splash {
        max-width: 100%;
        height: 100%;
        background-image: url("brightsplash.jpg");
        background-repeat: no-repeat;
        background-size: cover;
        cursor: pointer;
    }

    #post-splash {
        display: none;
    }
    </style>
</head>

<body>
    <div id="splash">
    </div>
    <div id="post-splash">
        <h1>Taylor Forrest</h1>
        <h2>photography</h2>
        <h2>About</h2>
        <h2>Portfolio</h2>
        <h2>Contact</h2>
    </div>
    <script>
    (function() {
        var splash = document.getElementById('splash'),
            postSplash = document.getElementById('post-splash');

        splash.addEventListener('click', function() {
            splash.style.display = "none";
            postSplash.style.display = "block";
        });

    })();
    </script>
</body>

</html>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-03-15
    • 1970-01-01
    • 1970-01-01
    • 2015-03-09
    • 1970-01-01
    • 2014-07-19
    • 2014-08-19
    • 2014-03-27
    相关资源
    最近更新 更多