我想寻求有关如何使倒数计时器响应的帮助。每次缩放窗口大小时,它仍会在中心的笔记本背景图像内对齐。我对媒体查询还不是很熟悉。另外,由于纸张设计嵌入在背景图像中,因此我发现将两者对齐很棘手。
(在编辑中添加了这个)我也忘了问和提到。在此代码中,它工作正常(几乎)。我只需要提到我在我的 css 上声明了其他 p{} 。所以我也想问我如何专门针对 .bg p{} ?因为看起来,我的 css 中的前一个 p{} 也会影响我正在处理的倒计时
这是代码 html
<div class="bg">
<p id="countdown"> </p>
</div>
css
.bg {
background-image: url('http://thefeministmegaphone.com/wp-content/uploads/2016/12/893146-notebook-wallpaper.jpg');
background-size: 100%;
background-repeat: no-repeat;
position:fixed;
width:100%;
height:100%;
left:0;
top:0;
text-align:center;
}
p#countdown {
transform: rotate(-5deg);
display:block;
color: #333;
font-size: 65px;
font-family:times;
margin: auto;
width: 60%;
padding: 10px;
top:50%;
}
@media screen and (width: 800px) {
.bg p {
font-size: .8em;
}
js
// Set the date we're counting down to
var countDownDate = new Date("Oct 14, 2017 10:00:00").getTime();
// Update the count down every 1 second
var x = setInterval(function() {
// Get todays date and time
var now = new Date().getTime();
// Find the distance between now an the count down date
var distance = countDownDate - now;
// Time calculations for days, hours, minutes and seconds
var days = Math.floor(distance / (1000 * 60 * 60 * 24));
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);
// Output the result in an element with id="countdown"
document.getElementById("countdown").innerHTML = days + "d " + hours + "h "
+ minutes + "m " + seconds + "s ";
// If the count down is over, write some text
if (distance < 0) {
clearInterval(x);
document.getElementById("countdown").innerHTML = "EXPIRED";
}
}, 1000);