所以我有一个星期五的作业来准备好我的投资组合,我决定将它做成一页滚动,但是如果没有bootstrap(不允许使用bootstrap),我似乎无法使scrollspy工作。有人知道我如何获得它吗?它起作用吗?
我尝试了不同种类的js脚本和jquery,但我似乎无法使它们正常工作https://codepen.io/axelnijsten/pen/VwwLQMV
<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"><head></div>
<div class="about-tags"></head></div>
<div class="about-tags"><body></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"></body></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/