locomotive scroll i want to scroll after click on spesfic div class with jquery lang
To scroll to a specific div class after clicking on it using jQuery, you can use the scrollTop() function. Here's an example:
HTML:
<button id="scrollButton">Scroll to Div</button>
<div class="scrollToDiv">Div 1</div>
<div class="scrollToDiv">Div 2</div>
<div class="scrollToDiv">Div 3</div>
CSS:
.scrollToDiv {
height: 200px;
margin-bottom: 20px;
background-color: #f2f2f2;
}
JavaScript (jQuery):
$(document).ready(function() {
$('#scrollButton').click(function() {
$('html, body').animate({
scrollTop: $('.scrollToDiv').eq(1).offset().top
}, 500);
});
});
In the above example, when the button with id "scrollButton" is clicked, it triggers a function that scrolls the page to the second div with the class "scrollToDiv". The animate() function is used to smoothly scroll the page to the specified div using the scrollTop property.
The eq(1) method is used to select the second div (index starts at 0). You can change the index value or use other methods like :eq() or :first to select the desired div based on your requirements.
Note: Make sure to include the jQuery library in your HTML file
原文地址: https://www.cveoy.top/t/topic/hNan 著作权归作者所有。请勿转载和采集!