gpt4 book ai didi

javascript - scrollspy 动画不会工作,我也不知道如何让它工作

转载 作者:太空宇宙 更新时间:2023-11-04 05:50:41 25 4
gpt4 key购买 nike

所以我周五有一项任务要准备好我的作品集,我决定把它做成一页滚动,但我似乎无法在没有 Bootstrap 的情况下让 scrollspy 工作(不允许使用 Bootstrap )有没有人知道如何我能让它工作吗?

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

<a href="https://codepen.io/axelnijsten/pen/VwwLQMV" rel="noreferrer noopener nofollow">https://codepen.io/axelnijsten/pen/VwwLQMV</a>

<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>

我希望当我点击联系人时,它会平滑地滚动到联系人部分

最佳答案

使用 Bootstrap 或 jQuery slideDown() 方法。

<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 Animate 方法。

    $(document).on('click','.goToSection',function(e){
$('html, body').animate({
scrollTop: $($(this).attr('data-href')).offset().top
}, 6000);//set second as required
})
 
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;
}

}
<!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 的工作演示。

关于javascript - scrollspy 动画不会工作,我也不知道如何让它工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58304894/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com