代码
Html代码:
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>上画滚动效果 - 梁先生哎</title>
<link rel="shortcut icon" href="https://liangxiansheng688.com.cn/favicon.ico" type="image/x-icon">
<script src="https://api.liangxiansheng688.com.cn/noconsole.js"></script>
</head>
<body>
<header id="home">
<div class="hero">
<div class="overlay"></div>
<h1>Scroll Magic</h1>
</div>
</header>
<div class="sticky-wrapper">
<nav>
<ul>
<li><a href="">Home</a></li>
<li><a href="">About</a></li>
<li><a href="">Terms</a></li>
<li><a href="">Services</a></li>
<li><a href="">Project</a></li>
<li><a href="">Faq</a></li>
</ul>
</nav>
</div>
<section id="item1">
<h1>Some Section</h1>
</section>
<section id="item2">
<h1>Other Section</h1>
</section>
</body>
</html>
CSS代码:
html,
body {
height: 100%;
padding: 0;
margin: 0;
font-family: sans-serif;
color: #fff;
}
h1 {
margin: 0;
display: table-cell;
vertical-align: middle;
text-align: center !important;
letter-spacing: 2px;
font-size: 80px;
font-weight: 400;
text-transform: uppercase;
}
h1::before,
h1::after {
content: '';
display: block;
width: 220px;
height: 1px;
border: 4px double #fff;
margin: 20px auto;
}
header {
height: calc(100% - 65px);
-webkit-appearance: 1500px;
perspective: 1500px;
perspective-origin: center bottom;
}
.hero {
position: relative;
background: #333 url(https://liangxiansheng688.com.cn/mainPage/1.jpg) no-repeat center center;
background-size: cover;
width: 100%;
height: 100%;
transform-origin: 50% 100%;
transform-style: preserve-3d;
}
.hero .overlay {
content: '';
display: block;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
opacity: 0;
background: linear-gradient(to bottom, rgba(0, 0, 0, 1) 0%, rgba(0, 0, 0, 0) 100%);
}
nav {
background: #000a1d;
height: 65px;
}
nav.fixed {
position: fixed;
top: 0;
left: 0;
right: 0;
}
.sticky-wrapper {
height: 65px;
}
nav ul {
list-style: none;
padding: 0;
margin: 0;
text-align: center;
}
nav ul li {
display: inline-block;
}
nav ul a {
height: 65px;
line-height: 65px;
padding: 10px 15px;
color: #a1a1a1;
font-size: 14px;
letter-spacing: 2px;
font-weight: 400;
text-transform: uppercase;
text-decoration: none;
}
section {
width: 100%;
height: 100%;
display: table;
}
section#item1 {
background: #000a1d;
font-family: sans-serif;
}
section#item2 {
background-image: url(https://liangxiansheng688.com.cn/1.jpg);
background-size: cover;
font-family: sans-serif;
}
JavaScript代码:
注意:该实例需要引入jQuery.js,如果您一时之间无法找到,可使用我们提供的链接:
<script type="text/javascript" src="https://liangxiansheng688.com.cn/jquery-2.2.4.min.js"></script>
<script src="https://llyth.cn/js/jquery-2.2.4.min.js"></script>
$(window).scroll(function() {
var heroHeight = $('header').height();
var yPosition = $(document).scrollTop();
if (yPosition <= heroHeight) {
var effectFactor = yPosition / heroHeight;
var rotation = effectFactor * (Math.PI / 2 - Math.asin((heroHeight - yPosition) / heroHeight));
$('.hero').css({
'-webkit-transform': 'rotateX('+rotation+'rad)',
'transform': 'rotateX('+rotation+'rad)',
})
.find('.overlay').css('opacity', effectFactor);
}
if (yPosition <= heroHeight) {
$('nav').removeClass('fixed');
} else {
$('nav').addClass('fixed');
}
});
声明:
本文采用
BY-NC-SA
协议进行授权,如无注明均为原创,转载请注明转自
Eric · 梦曦
本文地址: 实例:3d页面滚动效果
本文地址: 实例:3d页面滚动效果