gpt4 book ai didi

javascript - jQuery scrollTop 不适用于 CSS 视差?

转载 作者:行者123 更新时间:2023-11-29 18:03:42 25 4
gpt4 key购买 nike

我一直在制作一个使用视差的网站,其使用方式与 http://keithclark.co.uk/articles/pure-css-parallax-websites/demo3/ 中的使用方式非常相似。 ,并且我一直在尝试实现一些 jquery,这将使页面在页面加载时自动滚动到底部。但是,我使用的命令根本不会移动滚动条。我已经在静态网站上试过了,它似乎工作正常。

$(document).ready(function() {
$("html, body").animate({
scrollTop: $(document).height()
}, 2000);
return false;
});

我的代码(去掉文本)如下:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<link href='https://fonts.googleapis.com/css?family=Arvo' rel='stylesheet' type='text/css'>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<style>
.email a {
color: #001F67;
text-decoration: none;
}

a {
text-decoration: none;
}

.title {
text-align: center;
position: absolute;
left: 50%;
top: 50%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
color: Black;
font-size: 6vmin;
}

.About {
text-align: center;
position: absolute;
left: 50%;
top: 50%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
color: #001F67;
text-decoration: none;
font-size: 4vmin;
background-color: white;
}

.parallax {
height: 500px;
height: 100vh;
overflow-x: hidden;
overflow-y: auto;
-webkit-perspective: 300px;
perspective: 300px;
}

.parallax__group {
position: relative;
height: 500px;
height: 100vh;
-webkit-transform-style: preserve-3d;
transform-style: preserve-3d;
}

.parallax__layer {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
}

.parallax__layer--fore {
-webkit-transform: translateZ(90px) scale(.7);
transform: translateZ(90px) scale(.7);
z-index: 1;
}

.parallax__layer--base {
-webkit-transform: translateZ(0);
transform: translateZ(0);
z-index: 4;
}

.parallax__layer--back {
-webkit-transform: translateZ(-300px) scale(2);
transform: translateZ(-550px) scale(3);
z-index: 3;
}

.parallax__group {
-webkit-transition: -webkit-transform 0.5s;
transition: transform 0.5s;
}

body, html {
overflow: hidden;
}

body {
font: 100% / 1.5 Arvo;
}

* {
margin:0;
padding:0;
}

.parallax {
font-size: 200%;
}

#group2 {
z-index: 3;
}

#group2 .parallax__layer--back {
background: #FFFFFF;
}

#group3 {
z-index: 4;
}

#group3 .parallax__layer--base {
/*background: black;*/
}
</style>
<script>
$(document).ready(function() {
$("html, body").animate({
scrollTop: $(document).height()
}, 2000);
return false;
});
</script>
</head>
<body>
<div class="parallax">
<div id="group2" class="parallax__group">
<div class="parallax__layer parallax__layer--base">
</div>
<div class="parallax__layer parallax__layer--back">
<div class="title"><strong>Example Text</strong></div>
</div>
</div>
<div id="group3" class="parallax__group">
<div class="parallax__layer parallax__layer--fore">
<div class="About">
<!-- design inspired by graham hicks -->
<p>
Example Text
<p>
Example Text
</p>
<p class = "email">
<br /> Example Text
</p>
</div>
</div>
<div class="parallax__layer parallax__layer--base">
</div>
</div>
</div>
</body>
</html>

有人知道为什么这不起作用吗?

最佳答案

$("html, body") 更改为 $(".parallax") 以使其正常工作。

$(document).ready(function() {
$(".parallax").animate({
scrollTop: $(document).height()
}, 2000);
return false;
});

JSFiddle:https://jsfiddle.net/qs0vbbtx/

关于javascript - jQuery scrollTop 不适用于 CSS 视差?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33028228/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com