原生前端实现响应式个人简历网站设计(附源码)

本文介绍了作者如何使用HTML、CSS和JavaScript实现胜烨个人网站的响应式设计,包括滚动监听、服务和作品遮罩层、回到顶部按钮,以及光暗模式切换。还展示了如何通过ScrollReveal库实现页面滚动动画效果。
摘要由CSDN通过智能技术生成

网站站点

胜烨的个人网站

所用技术

  • HTML
  • css
  • JavaScript

实现功能

  • 响应式界面设计
  • 捕捉用户操作
  • 明暗模式
  • 服务器部署

视频展示

原生前端实现响应式个人简历网站设计(附源码)


源码

过于复杂了
这里只展示自己js的代码

/* 滑动监听 */
window.addEventListener("scroll", function () {
    const header = this.document.querySelector("header");
    header.classList.toggle("sticky", this.window.scrollY > 0)
})

/* 服务遮罩层 */
const serviceModals = document.querySelectorAll(".service-modal");
const learnmoreBtns = document.querySelectorAll(".learn-more-btn");
const modalCloseBtns = document.querySelectorAll(".modal-close-btn");

var modal = function (modalClick) {
    serviceModals[modalClick].classList.add("active");
}

learnmoreBtns.forEach(function (learnmoreBtn, i) {
    learnmoreBtn.addEventListener("click", () => {
        modal(i);
    });
});
modalCloseBtns.forEach((modalCloseBtn) => {
    modalCloseBtn.addEventListener("click", () => {
        serviceModals.forEach((modalView) => [
            modalView.classList.remove("active")
        ])
    })
})

/* 作品遮罩层 */
const portfolioModals = document.querySelectorAll(".portfolio-model");
const imgCards = document.querySelectorAll(".img-card");
const portfolioCloseBtns = document.querySelectorAll(".portfolio-close-btn");

var portfolioModal = function (modalClick) {
    portfolioModals[modalClick].classList.add("active");
}

imgCards.forEach(function (imgCard, i) {
    imgCard.addEventListener("click", () => {
        portfolioModal(i);
    });
});
portfolioCloseBtns.forEach((portfolioCloseBtn) => {
    portfolioCloseBtn.addEventListener("click", () => {
        portfolioModals.forEach((portfolioModalView) => {
            portfolioModalView.classList.remove("active")
        })
    })
})

/* 回到顶部按钮 */
const scrollTopbtn = document.querySelector(".scrollToTop-btn")
window.addEventListener("scroll", function () {

    scrollTopbtn.classList.toggle("active", window.scrollY > 500)
})

scrollTopbtn.addEventListener("click", () => {
    document.body.scrollTop = 0
    document.documentElement.scrollTop = 0
})

/* 页面滚动时导航菜单项处于活动状态 */
window.addEventListener("scroll", () => {
    const sections = document.querySelectorAll("section")
    const scrollY = window.pageYOffset

    sections.forEach(current => {
        let sectionHeight = current.offsetHeight;
        let sectionTop = current.offsetTop - 50;
        let id = current.getAttribute("id")

        if (scrollY > sectionTop && scrollY <= sectionTop + sectionHeight) {
            document.querySelector(".nav-items a[href*=" + id + "]").classList.add("active")
        } else {
            document.querySelector(".nav-items a[href*=" + id + "]").classList.remove("active")

        }
    })
})

/* 光暗模式切换 */
const themeBtn = document.querySelector(".theme-btn")
themeBtn.addEventListener("click", () => {
    document.body.classList.toggle("dark-theme")
    themeBtn.classList.toggle("sun")

    localStorage.setItem("saved-theme", getCurrentTheme())
    localStorage.setItem("saved-icon", getCurrentIcon())
})

const getCurrentTheme = () => {
    document.body.classList.contains("dark-theme") ? "dark" : "light"
}
const getCurrentIcon = () => {
    themeBtn.classList.contains("sun") ? "sun" : "moon"
}

const savedTheme = localStorage.getItem("saved-theme")
const savedIcon = localStorage.getItem("saved-icon")

if (savedTheme) {
    document.body.classList[savedTheme === "dark" ? "add" : "remove"]("dark-theme")
    themeBtn.classList[savedIcon === "sun" ? "add" : "remove"]("sun")
}

/* 缩小导航控制 */
const menuBtn = document.querySelector(".nav-menu-btn")
const closeBtn = document.querySelector(".nav-close-btn")
const navigation = document.querySelector(".navigation")
const navItems = document.querySelectorAll(".nav-items a")

menuBtn.addEventListener("click", () => {
    navigation.classList.add("active")
})

closeBtn.addEventListener("click", () => {
    navigation.classList.remove("active")
})

navItems.forEach((navItem) => {
    navItem.addEventListener("click", () => {
        navigation.classList.remove("active")
    })
})

/* 滑动动画 */
ScrollReveal({
    //reset: true,
    distance: '60px',
    duration: 2500,
    delay: 100
});

ScrollReveal().reveal('.home .info h2,.section-title-01,.section-title-02', {
    delay: 500,
    origin: 'left'
})
ScrollReveal().reveal('.home .info h3,.home .info p,.about-info .btn', {
    delay: 600,
    origin: 'right'
})
ScrollReveal().reveal('.home .info .btn', {
    delay: 700,
    origin: 'bottom'
})
ScrollReveal().reveal('.media-icons i, .contact-left li', {
    delay: 500,
    origin: 'left',
    interval: 200
})
ScrollReveal().reveal('.home-img, .about-img', {
    delay: 500,
    origin: 'bottom'
})
ScrollReveal().reveal('.about .description, .contact-right', {
    delay: 600,
    origin: 'right'
})
ScrollReveal().reveal('.about .professional-list li', {
    delay: 500,
    origin: 'right',
    interval: 200
})
ScrollReveal().reveal('.get-in-touch .containter .content ,.skills-description ,.services-description ,.contact-card,.contact-left h2', {
    delay: 700,
    origin: 'left',
})
ScrollReveal().reveal('.experience-card ,.service-card ,.education,.portfolio .img-card', {
    delay: 800,
    origin: 'bottom',
    interval:200
})
ScrollReveal().reveal('footer .group', {
    delay: 800,
    origin: 'top',
    interval:200
})

其中用到了一个外部的库,叫做scrollreveal,是一个滚动动画库
scrollreveal网站

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

申也.

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值