首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >滚动间谍动画无法工作,我也不知道如何使它工作。

滚动间谍动画无法工作,我也不知道如何使它工作。
EN

Stack Overflow用户
提问于 2019-10-09 13:07:34
回答 1查看 51关注 0票数 0

所以我周五有一项作业要做好我的投资组合,我决定把它变成一页卷轴,但是如果没有引导(不允许使用引导),我似乎不能让滚动间谍工作(不允许使用引导),有谁知道我怎么能让它工作呢?

我尝试过不同类型的js脚本和jquery,但我似乎无法让它们工作。

https://codepen.io/axelnijsten/pen/VwwLQMV

代码语言:javascript
复制
<div class="container">
    <div class="intro">
        <h1>Please explore</h1>
        <h1>and</h1>
        <h1>Discover.</h1>
        <br>
        <a href="#works"><input id="works" class= "button-8" type="submit" value="projects" name= " "></a>
    </div>  

我希望当我单击“联系人”时,它将顺利滚动到“联系人”部分。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-10-09 13:19:15

使用Bootstrap或jQuery slideDown()方法。

代码语言:javascript
复制
<a href="#contact" class="goToSection">Contact</a>
<a href="#CV" class="goToSection">CV</a>

<script type="text/javascript">
    $(document).on('click','.goToSection',function(e){
        e.preventDefault();
        $($(this).attr('href')).slideDown();
    })
</script>

第二种方法:

尝试jQuery动画方法。

代码语言:javascript
复制
    $(document).on('click','.goToSection',function(e){
        $('html, body').animate({
            scrollTop: $($(this).attr('data-href')).offset().top
        }, 6000);//set second as required
    })
代码语言:javascript
复制
        body{
        font-family: 'Red Hat Display', sans-serif;
        background-color: #2D3436;
        color: #EEEEEE;
        margin: 0;
        }

        .intro{
        font-size:30px;
        position: absolute;
        top: 160px;
        left: 10px;
        h1{
        margin-left: 20px;
        margin-top: 0;
        margin-bottom: 0;

        }
        }

        .navigation{
        text-align: center;
        font-size: 30px;
        position: relative;
        background-color: #202020;
        height: 604px;
        margin: 0;
        padding: 0;
        width: 550px;


        }

        .container {
        display: flex;
        flex-direction: column;
        margin: 0;
        flex-wrap: wrap;
        .navigation{
        align-self: flex-end;
        border-bottom-left-radius: 25%;
        div{
        display: flex;
        height: 500px;
        align-items: center;
        justify-content: center;
        margin-top: 20px;
        }

        a {
        text-decoration: none;
        color: #EEEEEE;
        padding: 10px;

        &:visited
        {
        color: #EEEEEE;
        }

        }

        }
        }

        .profile-image img{
        border-radius: 50%;
        }

        .button-8{
        color: black;
        background-color: #00CEC9;
        padding: 10px 15px;
        border: 2px solid;
        border-radius: 25px;
        width: 160px;
        border-color:  #00CEC9;
        font-size: 14px;
        font-weight: bold;
        margin-left: 25px;
        &:hover{
        background-color: aqua;
        border-color: aqua;
        cursor: pointer;
        }
        }

        .divider{
        text-align: center;
        font-size: 30px;
        margin: 20px 0 20px 0;
        }


        .works{
        text-align: center;
        justify-content: left;
        background-color: #202020;

        }

        .works-sub1{
        display: flex;
        text-align: left;
        justify-content: flex-start;
        img{
        height: 150px;
        width: 150px;
        margin-top: 20px;
        margin-left: 100px;
        margin-bottom: 20px;
        }
        p{
        padding: 10px;
        font-size: 25px;
        }
        }

        .works-sub2{
        display: flex;
        text-align: left;
        justify-content: flex-end;
        img{
        height: 150px;
        width: 150px;
        margin-right: 100px;
        }
        p{
        padding: 10px;
        font-size: 25px;
        text-align: right;
        }
        }

        .works-sub3{
        display: flex;
        text-align: left;
        justify-content: flex-start;
        img{
        height: 150px;
        width: 150px;
        margin-left: 100px;
        margin-top: 20px;
        margin-bottom: 40px;
        }
        p{
        padding: 10px;
        font-size: 25px;
        }
        }

        .about{
        display: flex;
        background-color: #2D3436;
        flex-direction: column;

        h1{
        text-align: left;
        margin-left: 30px;
        font-size: 40px;
        }
        }


        .about-tags{
        text-align: left;
        font-size: 25px;
        font-family: "Times New Roman", Times, serif;
        color: #00CEC9;
        padding-left: 20px;
        padding-bottom: 5px;
        }

        .about-content{
        text-align: right;
        font-size: 25px;
        padding-right: 20px;
        }

        .contact{
        display: flex;
        background-color: #202020;
        flex-direction: column;
        height: 500px;
        justify-content: center; 
        align-content: center;   
        }






        .contact-text{

        align-items: center;
        justify-content: center;
        p{
        margin: 0;
        font-size: 25px;
        display: flex;
        text-align: center;
        justify-content: center;
        }
        }


        .container-icons{
        display: flex;
        flex-direction: row;
        justify-content: space-evenly;
        align-items: flex-end;

        i{
        font-size: 25px;
        color: #00CEC9;
        padding-top: 150px;
        }

        }
代码语言:javascript
复制
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="res/css/style.css">
    <title>Portfolio</title>
   
</head>
<body>
    <div class="container">
        <div class="intro">
            <h1>Please explore</h1>
            <h1>and</h1>
            <h1>Discover.</h1>
            <br>
            <a href="#works"><input id="works" class= "button-8" type="submit" value="projects" name= " "></a>
        </div>  
        <div class="navigation" data-spy="scroll" data-target="#works">
            <a data-href="#contact" class="goToSection">Contact</a>
            <a data-href="#skills" class="goToSection">Skills</a>
            <a data-href="#works" class="goToSection">Works</a>
            <div class="profile-image">
                <img src="res/img/MokeyMokey-DAR.png">
            </div>
        </div>
        <div class="divider">
                <p>HTML - CSS - SCSS - JS</p>
        </div>
        <section id="works">
            <div class="works">
                <h1>Works</h1>
                <div class="works-sub1">
                    <img src="res/img/minesweeper.png">
                    <p>This is an interactible minesweeper box wich i made<br>
                                                        using flexbox.</p>
                </div>

                <div class="works-sub2">
                        <p>This is a chessboard wich i configured together
                                <br>using html and css. This was done with grid.</p>
                    <img src="res/img/chess.png">
                    
                </div>

                <div class="works-sub3">
                        <img src="res/img/minesweeper.png">
                        <p>This is an interactible minesweeper box wich i made<br>
                                                            using flexbox.</p>
                </div>
            </div>
        </section>
        <section id="skills">
            <div class="about">
                <h1 class="about-title">What I do (skills)</h1>
            
                <div class="about-tags">&lt;head&gt;</div>
                <div class="about-tags">&lt;/head&gt;</div>
                <div class="about-tags">&lt;body&gt;</div>
                    <div class="about-content">
                        <p>I design websites using Visual Studio Code.<br>
                        CSS, HTML and Sass is what I mainly use to 
                        <br>accomplish these things. </p>
                    </div>
                <div class="about-tags">&lt;/body&gt;</div>
            </div>
        </section>
        <section id="contact">
            <div class="contact">
                    <div class="contact-text"> 
                        (contact)
                           <p>If you are interested in what I <br>do you can contact me on the <br>following.</p>
                    </div>
                <div class="container-icons">
                    <i class="icon icon-envelop"></i>
                    <i class="icon icon-facebook"></i>
                    <i class="icon icon-instagram"></i>
                    <i class="icon icon-linkedin"></i>
                </div>
            </div>
        </section>
    </div>
    <script src="https://code.jquery.com/jquery-3.4.1.js" integrity="sha256-WpOohJOqMqqyKL9FccASB9O0KwACQJpFTUBLTYOVvVU=" crossorigin="anonymous"></script>
    <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js" integrity="sha256-VazP97ZCwtekAsvgPBSUwPFKdrwD3unUfSGVYrahUqU=" crossorigin="anonymous"></script>
</body>
</html>

请参阅使用您提供的html css的工作演示。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58304894

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档