【发布时间】:2017-06-30 04:42:13
【问题描述】:
所以我正在开发我的第一个项目——我自己的个人网页。我有一个背景动画,它本质上是一个脉动的循环图像。我希望能够让用户单击图像的“输入”部分并将其重定向到我的主页,或者单击整个页面上的任何位置。
我的背景动画与所有内容重叠,无论我尝试做什么,它都会覆盖任何类型的附加图像或文本框,我尝试创建点击和链接到我的主页。有人有什么建议吗?
html:
<!DOCTYPE html>
{% load staticfiles %}
<html lang="en">
<head>
<title>Test</title>
<meta charset="utf-8" />
<link rel="stylesheet" href="{% static 'personal/css/frontpagebackground.css' %}" type = "text/css"/>
</head>
<body>
<div class="animation"></div>
<div class="body"></div>
<a class="element" href="website.net/link" title="photo" id="element">photo</a>
</body>
</html>
css:
/* hide scroll bar. Y is vertical, x is horizontal*/
body {
margin:0;
padding:0;
overflow-y: hidden;
overflow-x: hidden;
}
/*pulsing background img */
.animation {
width: 100%;
height: 100%;
animation: pulse 6s infinite;
overflow:hidden;
background-color: black;
}
@keyframes pulse {
0% {
background-image: url('img/home2.jpg');
background-repeat: no-repeat;
background-position: center;
background-size: cover;
background-color: black;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
opacity: 1;
}
25% {
background-image: url('img/home.jpg');
background-repeat: no-repeat;
background-position: center;
background-size: cover;
background-color: black;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
opacity: 1;
}
50% {
background-image: url('img/home2.jpg');
background-repeat: no-repeat;
background-position: center;
background-size: cover;
background-color: black;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
opacity: 1;
}
75% {
background-image: url('img/home.jpg');
background-repeat: no-repeat;
background-position: center;
background-size: cover;
background-color: black;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
opacity: 1;
}
100% {
background-image: url('img/home2.jpg');
background-repeat: no-repeat;
background-position: center;
background-size: cover;
background-color: black;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
opacity: 1;
}
}
html,
body {
height: 100%;
}
【问题讨论】:
-
.animation应该是position: absolute; left: 0; top: 0;,否则下面会显示其他元素。 -
顺便说一句,在动画关键帧定义的每一步中,没有必要重复在整个动画中不改变的css属性。只需将它们添加到元素本身的选择器中即可。
标签: html css image animation background