JQuery implements simple scrolling animation effects and jquery scrolling Animation
The idea of animation is very simple. Click an element on the page and scroll to the specified position. The following describes my research results of Baidu in three hours:
First, the html section:
<Html> <body> <a> top </a> <a> center </a>... <p> continuous addition until the scroll bar appears </p>... </body>
Add two <a> elements as buttons. Then add the <a> element:
<Html> <body> <a href = "javascript:;" id = "tab1"> top </a> <a href = "javascript :; "id =" tab2 "> central </a>... <p> continuous addition until the scroll bar appears </p>... </body>
Href = "javascript:;" indicates that element a can activate javascript code. If no value is added, the code is invalid. <Button> is not required.
Then introduce jquery and write the code:
<script src="js/jquery-1.10.2.min.js"></script><script> $(document).ready(function(){ $("#tab1").click(function(){ $("html,body").animate({scrollTop:'0px'},300); }); $("#tab2").click(function(){ $("html,body").animate({scrollTop:'600px'},300); }); });</script>
Note:
1. It is best to write the code below the introduced jquery statement.
2. The id must correspond to the <a> element.
3. "html, body" indicates overall movement
4. ({scrollTop: '600px '}, 300). The preceding value is the moving distance, and the following value is the animation time (unit: milliseconds)
The code can be run at this step.
The following describes the jquery code in detail:
$ (Document ). ready (function () {// This sentence must be added. If this clause is not added, an error will occur and it does not work. $ ("# tab1 "). click (function () {// $ ("# tab1") is the selector, and click () is the method. # Tab1 uses the click method $ ("html, body "). animate ({scrollTop: '0px '}, 300); // The scrollTop I understand is a variable attribute that represents the distance between the top of the element and the edge of the display area of the current browser, therefore, if the distance between the upper edge of the body and the upper edge of the visible area of the browser is 0 PX, the result is to return to the top of the page. });...});
The above is all the content of this article, and I hope it will help you learn javascript programming.
Articles you may be interested in:
- JQuery scroll event Implementation Monitoring scroll bar paging example
- How to Implement js and jquery scrolling/redirecting a page to a specified position
- JQuery plug-in iScroll implements drop-down refresh and scrolling pages.
- How to dynamically load content during Page scrolling using jQuery
- JQuery implements smooth scrolling to a specified anchor
- JQuery multismultismultismultiscrocro
- Jquery implements simple seamless scrolling
- JQuery plug-in scroll for seamless scrolling
- On the scroll position scrollTop and scrollLeft of the jQuery page
- JQuery supports Image zoom-in and thumbnail image carousel code sharing