javascript - 我如何制作像这个网站 http://ejosue.com 这样的滑动框
问题描述
所以,我想做一个像这个网站一样的滑动框:http ://ejosue.com?Sorry ,但这是我第一次在 Stack Overflow 上提出问题,
解决方案
此代码取自可通过 google 搜索找到的许多示例!
来源:https ://codepen.io/villefalkenmark/pen/jbQKYv
$(window).on('scroll', function() {
$('.flip').each(function() {
var scrollTop = $(window).scrollTop(),
parentElementOffsetTop = $(this).parent().offset().top,
parentDistanceTop = (parentElementOffsetTop - scrollTop);
var elementHeight = $(this).height();
var distanceBottom = (parentDistanceTop + elementHeight);
var opacity = (distanceBottom / elementHeight);
var rotateSpeed = ((parentDistanceTop / 8).toFixed(2) * -1);
if (rotateSpeed <= 0) {
rotateSpeed = 0;
} else if (rotateSpeed >= 90) {
rotateSpeed = 90;
}
$(this).find(".pixel-counter").html(distanceBottom + "px is the parents bottom- distance to top of viewport");
$(this).css({
"transform": " translateY(0px) rotateX(" + rotateSpeed + "deg)",
"opacity": opacity
});
});
});
* {
margin: 0;
}
.container {
font-family: Arial;
width: 100%;
margin: 0 auto;
position: relative;
background-color: rgb(48, 48, 48);
}
.flip-parent {
position: relative;
perspective: 1200px;
vertical-align: baseline;
margin-bottom: -0px;
}
.flip {
-webkit-transform-origin: center bottom;
-moz-transform-origin: center bottom;
-ms-transform-origin: center bottom;
-o-transform-origin: center bottom;
/* transform-origin: center bottom; */
box-shadow: rgb(0, 0, 0) 0px 0px 0px 0px;
scale: (1);
transform: translateY(0px);
height: 800px;
width: 100%;
color: white;
font-size: 24px;
/* CENTER OUR CONTENT */
display: flex;
justify-content: center;
align-items: center;
}
.flip:before {
width: 100%;
z-index: 2;
text-transform: uppercase;
}
#first {
background-color: #D64541;
}
#second {
background-color: #59ABE3;
}
#third {
background-color: #E08283;
}
#fourth {
background-color: #E08283;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="container">
<section>
<div class="flip-parent">
<div class="flip" id="first">
<p class="pixel-counter"></p>
</div>
</div>
</section>
<section>
<div class="flip-parent">
<div class="flip" id="second">
<!--Since the section is tilting we need a constant linear value from our parent -->
<p class="pixel-counter"></p>
</div>
</div>
</section>
<section>
<div class="flip-parent">
<div class="flip" id="third">
<p class="pixel-counter"></p>
</div>
</div>
</section>
<section>
<div class="flip-parent">
<div class="flip" id="fourth">
<p class="pixel-counter"></p>
</div>
</div>
</section>
</div>
推荐阅读
- ios - 如何在 TableView Cells 中处理 Swift 组合订阅
- sql - 如何对两个表不同的列减法进行 Oracle DB 查询
- database - 将文本转换为整数并提取见解 - SQLITE
- python - match/case 语句在 PyCharm 中引发 SyntaxError
- python - 使用 python 读取谷歌存储桶文件
- java - 使用 jackson-dataformat-xml 库将属性设置为空 xml 标签
- logging - 如何将 NestJS 连接到 New Relic?
- c - 使用 SING_DFL 时未恢复 SIGINT 默认行为
- python - 封装 args 和 kwargs 的类
- sum - 随时间变化的变量总和 (AMPL)