我正在创建投资组合网站但我有问题将div(带有大量文本)元素与class&text; textFull'在背景图像下,在视口下。我认为z-index有点乱,但我不确定。如果我可以将渐变位置修复为“固定”,那将会很棒。
In this case the overflow(scroll bar) is not responding and i can't scroll
// where i generate random background image
const maxFiles = 159;
const randomEl = document.getElementById("random");
function randombg() {
var random = Math.floor(Math.random() * maxFiles)+1;
randomEl.style.backgroundImage = `url('image/(${random}).jpeg')`;
}
randombg();
//where i use typewriter plugin
$(document).ready(function(){
$('#header').typewrite({
blinkingCursor:false,
selectedBackground:"#141414",
selectedText:"#ffffff",
actions: [
{delay: 1000},
{type: 'Hello.'},
{delay: 1000},
{remove: {num: 6, type: 'stepped'}},
{type: 'Weclome '},
{delay: 1000},
{remove: {num: 1, type: 'stepped'}},
{select: {from: 10, to: 16}},
{delay: 1000},
{remove: {num: 5, type: 'stepped'}},
{delay: 1000},
{type: 'lcome to my site. '},
{type: '<br>'},
{delay: 1000},
{type: "I'm Atanas Bobev"},
{delay: 1000},
{remove: {num: 12, type: 'stepped'}},
{delay: 1000},
{type: "30 years old."},
{delay: 1000},
{remove: {num: 13, type: 'stepped'}},
{delay: 1000},
{type: "web designer."},
{select: {from: 26, to: 47}}
]
});
});
&#13;
@font-face {
font-family:TypeFont;
src: url(fonts/Lobster-Regular.ttf);
}
*{margin:0;padding:0;transition:1s;font-family:TypeFont;overflow-y:auto;overflow-x:hidden}
html,head,body{
height:100%;
width:100%;
}
/* The background gardient */
#an{
position:fixed;
background: linear-gradient(229deg, #a1c4fd, #c2e9fb, #cfd9df, #667eea, #764ba2, #e2d1c3, #89f7fe, #66a6ff, #48c6ef, #6f86d6, #feada6, #a3bded, #6991c7, #13547a, #80d0c7, #93a5cf, #434343, #000000, #93a5cf, #ff758c, #868f96, #596164, #c79081, #dfa579, #09203f, #96deda, #50c9c3, #29323c, #485563, #1e3c72, #2a5298, #b7f8db, #50a7c2, #2193b0, #6dd5ed);
background-size: 7400% 7400%;
animation: backgroundGardient 400s ease infinite;
z-index:15;
opacity:0.5;
width:100%;
height:100%;
-webkit-animation: backgroundGardient 400s ease infinite;
-moz-animation: backgroundGardient 400s ease infinite;
-o-animation: backgroundGardient 400s ease infinite;
animation: backgroundGardient 400s ease infinite;
}
@-webkit-keyframes backgroundGardient {
0% {
background-position: 0% 83%
}
50% {
background-position: 100% 18%
}
100% {
background-position: 0% 83%
}
}
@-moz-keyframes backgroundGardient {
0% {
background-position: 0% 83%
}
50% {
background-position: 100% 18%
}
100% {
background-position: 0% 83%
}
}
@-o-keyframes backgroundGardient {
0% {
background-position: 0% 83%
}
50% {
background-position: 100% 18%
}
100% {
background-position: 0% 83%
}
}
@keyframes backgroundGardient {
0% {
background-position: 0% 83%
}
50% {
background-position: 100% 18%
}
100% {
background-position: 0% 83%
}
}
/* Jquery stylesheet */
#jquery-script-menu {
position: fixed;
height: 90px;
width: 100%;
top: 0;
left: 0;
border-top: 5px solid #316594;
background: #fff;
-moz-box-shadow: 0 2px 3px 0px rgba(0, 0, 0, 0.16);
-webkit-box-shadow: 0 2px 3px 0px rgba(0, 0, 0, 0.16);
box-shadow: 0 2px 3px 0px rgba(0, 0, 0, 0.16);
z-index: 999999;
padding: 10px 0;
-webkit-box-sizing:content-box;
-moz-box-sizing:content-box;
box-sizing:content-box;
}
.jquery-script-center {
width: 960px;
margin: 0 auto;
}
.jquery-script-center ul {
width: 212px;
float:left;
line-height:45px;
margin:0;
padding:0;
list-style:none;
}
.jquery-script-center a {
text-decoration:none;
}
.jquery-script-ads {
width: 728px;
height:90px;
float:right;
}
.jquery-script-clear {
clear:both;
height:0;
}
/* The background image */
#random{
position:fixed;
background-position: center center;
background-size: cover;
background-repeat: no-repeat;
left: 0;
right: 0;
bottom: 0;
margin: auto;
min-width: 100vw;
min-height: 100vh;
background-size:cover;
background-repeat:no-repeat;
background-position:center center;
z-index:-2;
font-size:calc(1vh + 1vw);
}
#header > span.blinkingCursor{
display:none;
}
/* header with typewriter plugin */
h1#header{
z-index:15;
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
background-color: #ecf0f1;
color: black;
opacity: 0.7;
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=70)";
border: 20px solid #ecf0f1;
font-size: calc(2vh + 2vw + 1vmax + 0.5em);
font-weight: 100;
box-shadow: 0 3px 6px rgba(0, 0, 0, 0.16), 0 3px 6px rgba(0, 0, 0, 0.23);
}
/* The problem div */
.textFull{
position:absolute;
font-size: calc(2vh + 2vw);
left:0vw;
width:100vw;
background-color: white;
z-index:15;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<html>
<meta charset='utf-8'>
<script type="text/javascript" src="script/typeout.min.js"></script>
<script type="text/javascript" src="script/typewrite.min.js"></script>
<script type="text/javascript" src="script/jquery-3.3.1.min.js"></script>
<script type="text/javascript" src="script/typewrite.js"></script>
<head>
<style>
</style>
</head>
<body id='random'>
<div id='an'></div>
<h1 id='header'>Hi. I'm Atanas Bobev</h1>
<div class='textFull'>Lorem ipsum dollarum sit ametLorem ipsum dollarum sit ametLorem ipsum dollarum sit ametLorem ipsum dollarum sit ametLorem ipsum dollarum sit ametLorem ipsum dollarum sit ametLorem ipsum dollarum sit ametLorem ipsum dollarum sit ametLorem ipsum dollarum sit ametLorem ipsum dollarum sit ametLorem ipsum dollarum sit ametLorem ipsum dollarum sit ametLorem ipsum dollarum sit ametLorem ipsum dollarum sit ametLorem ipsum dollarum sit ametLorem ipsum dollarum sit ametLorem ipsum dollarum sit ametLorem ipsum dollarum sit ametLorem ipsum dollarum sit ametLorem ipsum dollarum sit ametLorem ipsum dollarum sit ametLorem ipsum dollarum sit ametLorem ipsum dollarum sit ametLorem ipsum dollarum sit ametLorem ipsum dollarum sit ametLorem ipsum dollarum sit ametLorem ipsum dollarum sit amet</div>
<script>
</script>
</body>
</html>
&#13;
问题代码:
.textFull{
position:absolute;
font-size: calc(2vh + 2vw);
left:0vw;
width:100vw;
background-color: white;
z-index:15;
}
答案 0 :(得分:0)
当您给出元素绝对定位时,您将其从文档流中拉出,以使其相对于未定位静态值(定位的默认值)的第一个父元素定位。
您需要做的是创建另一个允许您定位textFull元素的元素。这仍然可以通过绝对定位完成,但在下面的示例中,您可以看到它只是保留在普通文档中。此外,您还需要在身体以外的其他元素上设置背景图像,以便修复和允许滚动。
尝试在全屏模式下运行代码段以查看效果。
$(document).ready(function(){
$('#header').typewrite({
blinkingCursor:false,
selectedBackground:"#141414",
selectedText:"#ffffff",
actions: [
{delay: 300},
{type: 'Hello.'},
{delay: 1000},
{remove: {num: 6, type: 'stepped'}},
{type: 'Weclome '},
{delay: 1000},
{remove: {num: 1, type: 'stepped'}},
{select: {from: 10, to: 16}},
{delay: 1000},
{remove: {num: 5, type: 'stepped'}},
{delay: 1000},
{type: 'lcome to my site. '},
{type: '<br>'},
{delay: 1000},
{type: "I'm Atanas Bobev"},
{delay: 1000},
{remove: {num: 12, type: 'stepped'}},
{delay: 1000},
{type: "30 years old."},
{delay: 1000},
{remove: {num: 13, type: 'stepped'}},
{delay: 1000},
{type: "web designer."},
{select: {from: 26, to: 47}}
]
});
});
@import url('https://fonts.googleapis.com/css?family=Lobster');
* {
margin:0;
padding:0;
transition:1s;
font-family: 'Lobster', cursive;
}
html, body {
min-height:100vh;
width:100vw;
}
/* Jquery stylesheet */
#jquery-script-menu {
position: fixed;
height: 90px;
width: 100%;
top: 0;
left: 0;
border-top: 5px solid #316594;
background: #fff;
box-shadow: 0 2px 3px 0px rgba(0, 0, 0, 0.16);
z-index: 999999;
padding: 10px 0;
box-sizing:content-box;
}
/* The background image */
#random{
position: fixed;
left: 0;
right: 0;
bottom: 0;
margin: auto;
width: 100vw;
height: 100vh;
background-size:cover;
background-repeat:no-repeat;
background-position:center center;
z-index:-2;
font-size:calc(1vh + 1vw);
background-image: url('http://www.caryinstitute.org/sites/default/files/public/images/podcasts/pc_trees_forest.jpg');
}
#an {
position: fixed;
background: linear-gradient(229deg, #a1c4fd, #c2e9fb, #cfd9df, #667eea, #764ba2, #e2d1c3, #89f7fe, #66a6ff, #48c6ef, #6f86d6, #feada6, #a3bded, #6991c7, #13547a, #80d0c7, #93a5cf, #434343, #000000, #93a5cf, #ff758c, #868f96, #596164, #c79081, #dfa579, #09203f, #96deda, #50c9c3, #29323c, #485563, #1e3c72, #2a5298, #b7f8db, #50a7c2, #2193b0, #6dd5ed);
background-size: 7400% 7400%;
animation: backgroundGradient 400s ease infinite;
z-index:-1;
opacity:0.5;
width:100%;
height:100%;
}
@keyframes backgroundGradient {
0% {
background-position: 0% 83%
}
50% {
background-position: 100% 18%
}
100% {
background-position: 0% 83%
}
}
.full-pg-center {
height: 100vh;
width: 100vw;
display: flex;
align-items: center;
justify-content: center;
}
/* header with typewriter plugin */
h1#header {
background-color: #ecf0f1;
opacity: 0.7;
border: 20px solid #ecf0f1;
font-size: calc(2vh + 2vw + 1vmax + 0.5em);
font-weight: 100;
box-shadow: 0 3px 6px rgba(0, 0, 0, 0.16), 0 3px 6px rgba(0, 0, 0, 0.23);
}
#header > span.blinkingCursor{
display:none;
}
.textFull {
font-size: calc(2vh + 2vw);
background-color: white;
}
<div id='random'></div>
<div id='an'></div>
<div id='jquery-script-menu'>Menu</div>
<div class="full-pg-center">
<h1 id='header'>Hi. I'm Atanas Bobev</h1>
</div>
<div class="textFull">Lorem ipsum dollarum sit ametLorem ipsum dollarum sit ametLorem ipsum dollarum sit ametLorem ipsum dollarum sit ametLorem ipsum dollarum sit ametLorem ipsum dollarum sit ametLorem ipsum dollarum sit ametLorem ipsum dollarum sit ametLorem ipsum dollarum sit ametLorem ipsum dollarum sit ametLorem ipsum dollarum sit ametLorem ipsum dollarum sit ametLorem ipsum dollarum sit ametLorem ipsum dollarum sit ametLorem ipsum dollarum sit ametLorem ipsum dollarum sit ametLorem ipsum dollarum sit ametLorem ipsum dollarum sit ametLorem ipsum dollarum sit ametLorem ipsum dollarum sit ametLorem ipsum dollarum sit ametLorem ipsum dollarum sit ametLorem ipsum dollarum sit ametLorem ipsum dollarum sit ametLorem ipsum dollarum sit ametLorem ipsum dollarum sit ametLorem ipsum dollarum sit amet</div>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script type="text/javascript" src="https://cdn.rawgit.com/mrvautin/typewrite/master/dist/typewrite.min.js"></script>
这些是影响您的网页是否正常运行的其他一些因素:
HTML中的结构问题:
</body>
)标记。CSS问题:
您可能需要重新考虑动画渐变叠加层。非常复杂的渐变,不透明度设置和无限动画的组合在CPU上可能很重。使用Chrome中的开发人员工具,测试可能减少影响的不同方法。您可以从简化渐变开始(例如将其缩小为三种颜色)。我也会尝试使用rgba值作为渐变停止而不是opacity属性。此外,您可以尝试使背景尺寸更小。
祝你好运。