fullPage.js:网站单页滚动插件,真香

官网

fullPage.js:网站单页滚动插件,真香

https://alvarotrigo.com/fullPage/zh/

用途

通过调用本库可轻易创建全屏滚动网站(也称为单页网站)。 本库可创建全屏滚动网站,同时也可在网站中添加横向滚动条。

cdn引用

点击查看:https://cdnjs.com/libraries/fullPage.js

案例

详细使用文档参考:https://github.com/alvarotrigo/fullPage.js/tree/master/lang/chinese#fullpagejs

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>FullPage.js Example</title>
    <!-- 引入jQuery -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <!-- 引入fullPage.js -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/fullPage.js/3.1.2/fullpage.min.js"></script>
    <!-- 引入fullPage.js的CSS文件 -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fullPage.js/3.1.2/fullpage.min.css">
    <style>
        /* 自定义样式 */
        .section {
            text-align: center;
            position: relative;
            /* 为了相对定位 */
            background-size: cover;
            /* 调整背景图像以填充整个区域 */
            background-position: center;
            /* 将背景图像居中 */
        }

        .slide {
            text-align: center;
            position: relative;
            /* 为了相对定位 */
            background-size: cover;
            /* 调整背景图像以填充整个区域 */
            background-position: center;
            /* 将背景图像居中 */
        }

        .content {
            position: absolute;
            top50%;
            left50%;
            transformtranslate(-50%, -50%);
            color: white;
        }

        /* 导航菜单样式 */
        #navbar {
            position: fixed;
            top0;
            left0;
            width100%;
            background-color#333;
            padding10px 0;
            z-index1000;
        }

        #navbar ul {
            list-style: none;
            padding0;
            margin0 auto;
            max-width960px;
        }

        #navbar li {
            display: inline-block;
            margin-right20px;
        }

        #navbar a {
            color: white;
            text-decoration: none;
        }
    
</style>
</head>

<body>
    <nav id="navbar">
        <ul>
            <li><a href="#section1">Section 1</a></li>
            <li><a href="#section2">Section 2</a></li>
            <li><a href="#section3">Section 3</a></li>
            <li><a href="#section4">Section 4</a></li>
            <li><a href="#section4/1">Section 5</a></li>
        </ul>
    </nav>
    <div id="fullpage">
        <div class="section" id="section1"
            style="background-image: url('https://desk-fd.zol-img.com.cn/t_s960x600c5/g4/M08/0C/09/Cg-4WVSBfl-IanN7AC__cIPrv8EAAR5PQMDkT8AL_-I272.jpg');">

            <div class="content">
                <h2>Section 1</h2>
                <p>This is the content of section 1.</p>
            </div>
        </div>
        <div class="section" id="section2"
            style="background-image: url('https://desk-fd.zol-img.com.cn/t_s960x600c5/g5/M00/02/08/ChMkJ1bKzFWIZlBXAD2We1G9mDsAALI1QAOSgkAPZaT215.jpg');">

            <div class="content">
                <h2>Section 2</h2>
                <p>This is the content of section 2.</p>
            </div>
        </div>
        <div class="section" id="section3"
            style="background-image: url('https://desk-fd.zol-img.com.cn/t_s960x600c5/g5/M00/02/08/ChMkJlbKzFWIZNvSABBYF9awqNAAALI1QDmg-YAEFgv220.jpg');">

            <div class="content">
                <h2>Section 3</h2>
                <p>This is the content of section 3.</p>
            </div>
        </div>
        <div class="section" id="section4">
            <div class="slide"
                style="background-image: url('https://images.pexels.com/photos/842711/pexels-photo-842711.jpeg?auto=compress&cs=tinysrgb&w=600');">

                <h1>Smple Demo</h1>
            </div>
            <div class="slide"
                style="background-image: url('https://images.pexels.com/photos/1435075/pexels-photo-1435075.jpeg?auto=compress&cs=tinysrgb&w=600');">

                <h1>Only text</h1>
            </div>
        </div>
    </div>

    <script>
        // 初始化fullPage.js
        $(document).ready(function ({
            $('#fullpage').fullpage({
                // 滚动速度
                scrollingSpeed1000,
                // 自动滚动
                autoScrollingtrue,
                // 锚点
                anchors: ['section1''section2''section3''section4'],
                // 导航条
                navigationtrue,
                // 导航条位置
                navigationPosition'right',
                // 控制箭头
                controlArrowstrue,
                // 水平循环
                loopHorizontaltrue,
                // 键盘滚动
                keyboardScrollingtrue,
                // 垂直居中
                verticalCenteredtrue,
                // 分段颜色
                sectionsColor: ['#f2f2f2''#e6e6e6''#cccccc'],
                // 响应式宽度
                responsiveWidth768,
                // 响应式高度
                responsiveHeight0,
                // 滚动溢出
                scrollOverflowtrue
            });
        });

    
</script>
</body>

</html>

这个设计还是很惊艳的,容易上手,可以将上面的案例来跑一下,更详细的用法请参考官方教程。

原文始发于微信公众号(编程亿点有趣):fullPage.js:网站单页滚动插件,真香

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/271044.html

(0)
飞熊的头像飞熊bm

相关推荐

发表回复

登录后才能评论
极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!