-1
I own a element <a>
in my .html
, where I need that when there was the event of onclick
in the same, would occur the transitional effect of session, that is to say:
With the event
onclick
in the element<a>
automatically it would transit between each session of my<body>
.
What I managed to develop was the following:
In accordance with the every click in the element the same goes down every session.
<!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">
<title>Document</title>
</head>
<body>
<div id="scroll">
<a href="#" class="defaut-btn-gradient -button scroll"><i class="fas fa-angle-double-left"></i> Scroll Down</a>
</div>
<div class="section" id="section1"></div>
<div class="section" id="section2"></div>
<script>
var secs = document.querySelectorAll('.section');
var currentSection = 0;
document.querySelector('#scroll').addEventListener('click', move);
function move(e) {
if (e.target.classList.contains('scroll') && currentSection < secs.length) {
window.scroll({
top: secs[++currentSection].offsetTop,
left: 0,
behavior: 'smooth'
});
// secs[++currentSection].scrollIntoView({ behavior: 'smooth' });
} else if (currentSection > 0) {
window.scroll({
top: secs[--currentSection].offsetTop,
left: 0,
behavior: 'smooth'
});
}
}
</script>
</body>
</html>
I suggest you read the community guidelines to create a good question, it is a bit confusing and you need to post all the code referring to the subject of the question, to improve the analysis of users.
– user148754