/* 创建底部边框 */
.nav-son::before {
content: "";
position: absolute;
bottom: -3px; /* 将伪元素定位到导航栏项的底部 */
left: 0;
width: 100%;
height: 4px; /* 边框高度 */
border-radius: 15px;
background-color: rgb(0, 125, 255);
transform: scaleX(0); /* 初始状态下将宽度缩放为0,隐藏边框 */
transform-origin: left center; /* 设置变换原点为左侧中心 */
transition: transform 0.3s; /* 设置过渡属性和过渡时间 */
}
backdrop-filter: blur(5px); /* 添加高斯模糊效果 */
<script src="js/live2d-widget-master/autoload.js""></script>
::-webkit-scrollbar {
width: 6px;
height: 6px;
}
::-webkit-scrollbar-thumb {
background-color: #4B5563;
border-radius: 25px;
}
::-webkit-scrollbar-track, body.dark::-webkit-scrollbar-thumb {
background-color: #eee;
}
滚动回去则会变回原样,这里利用js实现
// 导航栏js
var nav = document.querySelector('.nav');
window.addEventListener('scroll', function() {
var scrollTop = window.pageYOffset || document.documentElement.scrollTop;
if (scrollTop > 0) {
// 滚动条不在顶部时的样式
nav.style.width = '100%';
nav.style.borderRadius = '0';
nav.style.top = '0px';
nav.style.backgroundColor = 'rgba(38, 38, 38, 0.8)';
nav.style.transition = 'all 1s'; // 添加过渡效果
// 鼠标悬停时的样式
nav.addEventListener('mouseover', function() {
nav.style.backgroundColor = 'rgba(51, 51, 51, 0.8)';
});
nav.addEventListener('mouseout', function() {
nav.style.backgroundColor = 'rgba(51, 51, 51, 0.8)';
});
} else {
// 滚动条在顶部时的样式
nav.style.width = '95%';
nav.style.borderRadius = '15px';
nav.style.top = '30px';
nav.style.backgroundColor = 'rgba(51, 51, 51, 0)';
nav.style.transition = 'all 1s'; // 添加过渡效果
// 鼠标悬停时的样式
nav.addEventListener('mouseover', function() {
nav.style.backgroundColor = 'rgba(51, 51, 51, 1)';
});
nav.addEventListener('mouseout', function() {
nav.style.backgroundColor = 'rgba(51, 51, 51, 0)';
});
}
});
window.addEventListener('load', function() {
var backgroundCount = 31; // 背景图像的总数
var displayPics = document.querySelectorAll('.display-pic'); // 获取所有 display-pic 元素
// 遍历每个 display-pic 元素
displayPics.forEach(function(displayPic) {
var randomIndex = Math.floor(Math.random() * backgroundCount) + 1; // 生成 1 到 backgroundCount 的随机整数
displayPic.src = './img/background' + randomIndex + '.jpg'; // 设置当前 display-pic 元素的图片路径
});
});
/* 左浮动 */
.left {
float: left;
}
/* 右浮动 */
.right {
float: right;
}
然后用js遍历单数和偶数,并添加浮动方向的类名
window.addEventListener('load', function() {
var exhibits = document.querySelectorAll('.exhibit');
var introduce = document.querySelectorAll('.introduce');
var date = document.querySelectorAll('.date');
var contentTitle = document.querySelectorAll('.content-title');
var postMeta = document.querySelectorAll('.post-meta');
var postMain = document.querySelectorAll('.post-main');
for (var i = 0; i < exhibits.length; i++) {
if (i % 2 === 0) {
exhibits[i].classList.add('left');
introduce[i].classList.add('right');
date[i].classList.add('right');
contentTitle[i].classList.add('right');
postMeta[i].classList.add('right');
postMain[i].classList.add('right');
} else {
exhibits[i].classList.add('right');
introduce[i].classList.add('left');
date[i].classList.add('left');
contentTitle[i].classList.add('left');
postMeta[i].classList.add('left');
postMain[i].classList.add('left');
}
}
});
window.addEventListener('load', function() {
var articleTitle = document.querySelector('.article-title');
var main = document.querySelector('.main');
articleTitle.style.opacity = '0'; // 初始状态设置为透明
main.style.opacity = '0';
articleTitle.style.transform = 'translateY(-100%)'; // 初始状态设置为位于上方
main.style.transform = 'translateY(100%)';// 初始状态设置为位于下方
setTimeout(function() {
articleTitle.style.transition = 'opacity 1.5s ease-in-out, transform 1s ease-in-out'; // 添加过渡效果
articleTitle.style.opacity = '1'; // 设置结束状态为完全显现
articleTitle.style.transform = 'translateY(0)'; // 设置结束状态为位于原始位置
main.style.transition = 'opacity 2s ease-in-out, transform 1.5s ease-in-out'; // 添加过渡效果
main.style.opacity = '1'; // 设置结束状态为完全显现
main.style.transform = 'translateY(0)'; // 设置结束状态为位于原始位置
}, 100);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r75/three.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/1.18.0/TweenMax.min.js"></script>
<script src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/175711/bas.js"></script>
.shell:before {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
background: rgba(99, 99, 99, 0.8);
content: "";
}
鼠标向下滚动,当鼠标滚动时,触发滚动事件,并且检测滚动距离,获取当前时间轴项目的最小和最大高度,如果当前滚动位置在当前项目的最小和最大高度之间,则将当前项目设置为激活状态,并设置背景图片为当前项目的图片,如果滚动到最后一个项目,并且超过了当前项目高度的一半,则将最后一个项目设置为激活状态,并设置背景图片为最后一个项目的图片。
(function () {
var timeline = function (id) {
var selectors = {
id: document.querySelector(id),
item: document.querySelectorAll(id + " .item"),
activeClass: "item--active",
img: ".img"
};
// 将第一个时间轴项目激活,并设置时间轴背景图片为第一个项目的图片
selectors.item[0].classList.add(selectors.activeClass);
selectors.id.style.backgroundImage = 'url(' + selectors.item[0].querySelector(selectors.img).src + ')';
// 获取时间轴项目的总数
var itemLength = selectors.item.length;
// 当页面滚动时,触发滚动事件
window.onscroll = function () {
var max, min;
// 获取页面滚动的距离
var pos = window.pageYOffset;
Array.prototype.forEach.call(selectors.item, function (element, i) {
// 获取当前时间轴项目的最小和最大高度
min = element.offsetTop;
max = element.offsetHeight + element.offsetTop;
// 如果滚动到最后一个项目,并且超过了当前项目高度的一半,
// 则将最后一个项目设置为激活状态,并设置背景图片为最后一个项目的图片
if (i == itemLength - 2 && pos > min + element.offsetHeight / 2) {
Array.prototype.forEach.call(selectors.item, function (element) {
element.classList.remove(selectors.activeClass);
});
selectors.id.style.backgroundImage = 'url(' + selectors.item[itemLength - 1].querySelector(selectors.img).src + ')';
selectors.item[itemLength - 1].classList.add(selectors.activeClass);
}
// 如果当前滚动位置在当前项目的最小和最大高度之间,
// 则将当前项目设置为激活状态,并设置背景图片为当前项目的图片
else if (pos <= max - 10 && pos >= min) {
selectors.id.style.backgroundImage = 'url(' + element.querySelector(selectors.img).src + ')';
Array.prototype.forEach.call(selectors.item, function (element) {
element.classList.remove(selectors.activeClass);
});
element.classList.add(selectors.activeClass);
}
});
};
};
timeline("#shell");
})();
@media only screen and (max-width: 820px) {
.bottom{
width: 450px;
}
.article{
width: 450px;
height: 560px;
margin: 30px auto;
}
.article::after{
content: "";
display: block;
clear: both;
}
.content{
width: 450px;
}
.introduce{
width: 450px;
height: 270px;
}
}
@media only screen and (max-width: 820px) {
.bottom,.title,.inscription{
width: 450px;
}
img{
width: 450px !important;
}
.comment{
width: 400px;
}
}
@media only screen and (max-width: 820px) {
canvas:nth-child(1){
margin-top: 0px;
width: 450px !important;
height: 470px !important;
left: 0%;
}
}
@media only screen and (max-width: 820px) {
.item {
align-self: baseline !important;
width: 100%;
padding: 0 30px 150px 80px;
}
.item:before {
left: 10px !important;
padding: 0 !important;
top: 50px;
text-align: center !important;
width: 60px;
border: none !important;
}
.item:last-child {
padding-bottom: 40px;
}
}
@media only screen and (max-width: 820px) {
.timeline:before {
left: 40px;
}
}
<div class="components">
<div class="main-button">
<div class="moon"></div>
<div class="moon"></div>
<div class="moon"></div>
</div>
<div class="daytime-backgrond"></div>
<div class="daytime-backgrond"></div>
<div class="daytime-backgrond"></div>
<div class="cloud">
<div class="cloud-son"></div>
<div class="cloud-son"></div>
<div class="cloud-son"></div>
<div class="cloud-son"></div>
<div class="cloud-son"></div>
<div class="cloud-son"></div>
</div>
<div class="cloud-light">
<div class="cloud-son"></div>
<div class="cloud-son"></div>
<div class="cloud-son"></div>
<div class="cloud-son"></div>
<div class="cloud-son"></div>
<div class="cloud-son"></div>
</div>
<div class="stars">
<div class="star big">
<div class="star-son"></div>
<div class="star-son"></div>
<div class="star-son"></div>
<div class="star-son"></div>
</div>
<div class="star big">
<div class="star-son"></div>
<div class="star-son"></div>
<div class="star-son"></div>
<div class="star-son"></div>
</div>
<div class="star medium">
<div class="star-son"></div>
<div class="star-son"></div>
<div class="star-son"></div>
<div class="star-son"></div>
</div>
<div class="star medium">
<div class="star-son"></div>
<div class="star-son"></div>
<div class="star-son"></div>
<div class="star-son"></div>
</div>
<div class="star medium">
<div class="star-son"></div>
<div class="star-son"></div>
<div class="star-son"></div>
<div class="star-son"></div>
</div>
<div class="star small">
<div class="star-son"></div>
<div class="star-son"></div>
<div class="star-son"></div>
<div class="star-son"></div>
</div>
<div class="star small">
<div class="star-son"></div>
<div class="star-son"></div>
<div class="star-son"></div>
<div class="star-son"></div>
</div>
<div class="star small">
<div class="star-son"></div>
<div class="star-son"></div>
<div class="star-son"></div>
<div class="star-son"></div>
</div>
<div class="star small">
<div class="star-son"></div>
<div class="star-son"></div>
<div class="star-son"></div>
<div class="star-son"></div>
</div>
<div class="star small">
<div class="star-son"></div>
<div class="star-son"></div>
<div class="star-son"></div>
<div class="star-son"></div>
</div>
<div class="star small">
<div class="star-son"></div>
<div class="star-son"></div>
<div class="star-son"></div>
<div class="star-son"></div>
</div>
</div>
</div>
.star-son{
float: left;
}
/* 大星星 */
.big .star-son:nth-child(1){
width: 7.5px;
height: 7.5px;
background-image: radial-gradient(circle 7.5px at left 0, transparent 7.5px, #fff);
}
.big .star-son:nth-child(2){
width: 7.5px;
height: 7.5px;
background-image: radial-gradient(circle 7.5px at right 0, transparent 7.5px, #fff);
}
.big .star-son:nth-child(3){
width: 7.5px;
height: 7.5px;
background-image: radial-gradient(circle 7.5px at 0 bottom, transparent 7.5px, #fff);
}
.big .star-son:nth-child(4){
width: 7.5px;
height: 7.5px;
background-image: radial-gradient(circle 7.5px at right bottom, transparent 7.5px, #fff);
}
transition: 0.7s;
transition-timing-function: cubic-bezier( 0,0.5, 1.3,1);