Home >Web Front-end >JS Tutorial >How Can I Use jQuery to Smoothly Scroll to the Last Element on a Page After Clicking a Specific Input?
Scrolling to an Element with jQuery
In the context of a web page with various elements, such as input fields,
To achieve this, we can utilize the jQuery library's animation feature. The following code snippet exemplifies the desired behavior:
$("#subject").click(function() { $([document.documentElement, document.body]).animate({ scrollTop: $("#submit").offset().top }, 2000); });
Explanation:
Note: The provided code assumes that the submit button with the ID "#submit" is the last item on the page. If this is not the case, you can adjust the code to target the desired element.
The above is the detailed content of How Can I Use jQuery to Smoothly Scroll to the Last Element on a Page After Clicking a Specific Input?. For more information, please follow other related articles on the PHP Chinese website!