При нажатии на иконку перейти к другой секции
Как при нажатии на иконку стрелки перейти к следующей секции с текстом?
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
section {
height: 100vh;
width: 100%;
display: table;
}
section.title {
background-color: coral;
}
section.text {
background-color: white;
}
h1,
p {
display: table-cell;
text-align: center;
vertical-align: middle;
}
.arrow {
position: absolute;
bottom: 30px;
left: 50%;
margin-left: -16px;
display: block;
width: 32px;
height: 32px;
border: 2px solid #FFF;
background-size: 14px auto;
border-radius: 50%;
z-index: 2;
-webkit-animation: bounce 2s infinite 2s;
animation: bounce 2s infinite 2s;
-webkit-transition: all .2s ease-in;
transition: all .2s ease-in;
transform: scale(1) opacity: 1;
-webkit-transition: all .5s ease-in 3s;
transition: all .5s ease-in 3s;
}
.arrow:before {
position: absolute;
top: calc(50% - 8px);
left: calc(50% - 7px);
transform: rotate(-45deg);
display: block;
width: 12px;
height: 12px;
content: "";
border: 2px solid white;
border-width: 0px 0 2px 2px;
}
@keyframes bounce {
0%,
100%,
20%,
50%,
80% {
-webkit-transform: translateY(0);
-ms-transform: translateY(0);
transform: translateY(0);
}
40% {
-webkit-transform: translateY(-10px);
-ms-transform: translateY(-10px);
transform: translateY(-10px);
}
60% {
-webkit-transform: translateY(-5px);
-ms-transform: translateY(-5px);
transform: translateY(-5px);
}
}
<section class="title">
<h1>Заголовок</h1>
<a href="#" class="arrow" address="true"></a>
</section>
<section class="text">
<p>Текст</p>
</section>
Ответы (3 шт):
Автор решения: soledar10
→ Ссылка
Пример
const btnArrow = document.querySelector(".arrow");
const sectionText = document.querySelector(".text");
function scrollTo(element) {
window.scroll({
behavior: 'smooth',
left: 0,
top: element.offsetTop
});
}
btnArrow.addEventListener('click', () => {
scrollTo(sectionText);
});
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
section {
height: 100vh;
width: 100%;
display: table;
}
section.title {
background-color: coral;
}
section.text {
background-color: white;
}
h1,
p {
display: table-cell;
text-align: center;
vertical-align: middle;
}
.arrow {
position: absolute;
bottom: 30px;
left: 50%;
margin-left: -16px;
display: block;
width: 32px;
height: 32px;
border: 2px solid #FFF;
background-size: 14px auto;
border-radius: 50%;
z-index: 2;
-webkit-animation: bounce 2s infinite 2s;
animation: bounce 2s infinite 2s;
-webkit-transition: all .2s ease-in;
transition: all .2s ease-in;
transform: scale(1) opacity: 1;
-webkit-transition: all .5s ease-in 3s;
transition: all .5s ease-in 3s;
}
.arrow:before {
position: absolute;
top: calc(50% - 8px);
left: calc(50% - 7px);
transform: rotate(-45deg);
display: block;
width: 12px;
height: 12px;
content: "";
border: 2px solid white;
border-width: 0px 0 2px 2px;
}
@keyframes bounce {
0%,
100%,
20%,
50%,
80% {
-webkit-transform: translateY(0);
-ms-transform: translateY(0);
transform: translateY(0);
}
40% {
-webkit-transform: translateY(-10px);
-ms-transform: translateY(-10px);
transform: translateY(-10px);
}
60% {
-webkit-transform: translateY(-5px);
-ms-transform: translateY(-5px);
transform: translateY(-5px);
}
}
<section class="title">
<h1>Заголовок</h1>
<a href="#" class="arrow" address="true"></a>
</section>
<section class="text">
<p>Текст</p>
</section>
Автор решения: Sevastopol'
→ Ссылка
$(function() {
$('.arrow').click(function() {
$('html, body').animate({
scrollTop: $('section.text').offset().top
}, 'slow');
return false;
});
});
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
section {
height: 100vh;
width: 100%;
display: table;
}
section.title {
background-color: coral;
}
section.text {
background-color: white;
}
h1,
p {
display: table-cell;
text-align: center;
vertical-align: middle;
}
.arrow {
position: absolute;
bottom: 30px;
left: 50%;
margin-left: -16px;
display: block;
width: 32px;
height: 32px;
border: 2px solid #FFF;
background-size: 14px auto;
border-radius: 50%;
z-index: 2;
-webkit-animation: bounce 2s infinite 2s;
animation: bounce 2s infinite 2s;
-webkit-transition: all .2s ease-in;
transition: all .2s ease-in;
transform: scale(1) opacity: 1;
-webkit-transition: all .5s ease-in 3s;
transition: all .5s ease-in 3s;
}
.arrow:before {
position: absolute;
top: calc(50% - 8px);
left: calc(50% - 7px);
transform: rotate(-45deg);
display: block;
width: 12px;
height: 12px;
content: "";
border: 2px solid white;
border-width: 0px 0 2px 2px;
}
@keyframes bounce {
0%,
100%,
20%,
50%,
80% {
-webkit-transform: translateY(0);
-ms-transform: translateY(0);
transform: translateY(0);
}
40% {
-webkit-transform: translateY(-10px);
-ms-transform: translateY(-10px);
transform: translateY(-10px);
}
60% {
-webkit-transform: translateY(-5px);
-ms-transform: translateY(-5px);
transform: translateY(-5px);
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<section class="title">
<h1>Заголовок</h1>
<a href="#" class="arrow" address="true"></a>
</section>
<section class="text">
<p>Текст</p>
</section>
Автор решения: Sevastopol'
→ Ссылка
$(document).ready(function(){
$('a[href^="#"], a[href^="."]').click( function(e){
var scroll_el = $(this).attr('href');
if ($(scroll_el).length != 0) {
$('html, body').animate({ scrollTop: $(scroll_el).offset().top }, 500);
}
e.preventDefault();
});
});
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
section {
height: 100vh;
width: 100%;
display: table;
}
section.title {
background-color: coral;
}
section.text {
background-color: white;
}
h1,
p {
display: table-cell;
text-align: center;
vertical-align: middle;
}
.arrow {
position: absolute;
bottom: 30px;
left: 50%;
margin-left: -16px;
display: block;
width: 32px;
height: 32px;
border: 2px solid #FFF;
background-size: 14px auto;
border-radius: 50%;
z-index: 2;
-webkit-animation: bounce 2s infinite 2s;
animation: bounce 2s infinite 2s;
-webkit-transition: all .2s ease-in;
transition: all .2s ease-in;
transform: scale(1) opacity: 1;
-webkit-transition: all .5s ease-in 3s;
transition: all .5s ease-in 3s;
}
.arrow:before {
position: absolute;
top: calc(50% - 8px);
left: calc(50% - 7px);
transform: rotate(-45deg);
display: block;
width: 12px;
height: 12px;
content: "";
border: 2px solid white;
border-width: 0px 0 2px 2px;
}
@keyframes bounce {
0%,
100%,
20%,
50%,
80% {
-webkit-transform: translateY(0);
-ms-transform: translateY(0);
transform: translateY(0);
}
40% {
-webkit-transform: translateY(-10px);
-ms-transform: translateY(-10px);
transform: translateY(-10px);
}
60% {
-webkit-transform: translateY(-5px);
-ms-transform: translateY(-5px);
transform: translateY(-5px);
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<section class="title">
<h1>Заголовок</h1>
<a href="#text" class="arrow" address="true"></a>
</section>
<section id="text" class="text">
<p>Текст</p>
</section>