jquery animation effects animate and ScrollTop use instances together

Source: Internet
Author: User

CSS property values are changed gradually so that you can create animation effects. Only numeric values can create animations (such as "margin:30px"). String values cannot create animations (such as "background-color:red").

Copy CodeThe code is as follows: $ (' #shang '). Click (function () {$ (' html,body '). Animate ({scrolltop: ' 0px '}, 800);});

The above code indicates that the scroll bar jumps to 0, and the page movement speed is 800. Practical examples of combining scrolltop:

Copy CodeThe code is as follows: JQuery (document). Ready (function ($) {$ (' #shang '). Click (function () {$ (' html,body '). Animate ({scrolltop: ' 0px '},  800);  });  $ (' #comt '). Click (function () {$ (' html,body '). Animate ({scrolltop:$ (' #comments '). Offset (). Top}, 800);  });  $ (' #xia '). Click (function () {$ (' html,body '). Animate ({scrolltop:$ (' #footer '). Offset (). Top}, 800); }); });

Click the relevant ID to move to the specified location: Click on the element with ID Shang, go back to the top, click on the element with ID COMT, return to the location with ID comments, click on the element with ID Xia, and go back to the bottom;

How to realize ScrollTop method in jquery.animate by native JS

    • jquery
    •                                                                         
    • JavaScript
    •                                                                

RadicalDecember 02, 2016 question                            

  • concern4 Follow                              
  • collection                                                                                                            0 favorites, 1k Browse                               

The problem is helpful, the content is complete, and I want to know the answer . 0 problems have no real value, lack of key content, no room for improvement

Can't find a good introduction to the Internet to achieve,

$(‘html, body‘).animate({  scrollTop: 800}, 1000)

How to control this scrolltop time?

    • December 02, 2016 question
    • Comments
    • Invitation to answer
    • Edit
      • Report
      • Shut down
xComments Support Section Markdown syntax: **bold** _italic_ [link](http://example.com) > 引用 `code` -                         列表。 At the same time, you will be notified by your @ user See all 3 answersthe answer is helpful to the person, has the reference value 0 The answer is no help, it's the wrong answer, irrelevantly replying .

What you need to do is not control the time, but control the step size, such as 800px,800ms, is 800ms within the 800px, if it is 1600px, then 800ms within the move 1600px

jquery animation effects animate and ScrollTop use instances together

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.