Home>Article>Daily Programming> How to achieve the effect of clicking on the web page to return to the top in jquery? (Pictures + Videos)
This article mainly introduces how to use jquery code to achieve the effect of returning the web page to the top.
When we browse the pages of major websites, we must all have encountered it. When browsing a long page, when you scroll to the lower part, a button effect similar to the return to the top will appear.
This special effect of clicking back to the top can greatly improve the user experience. Then it is very simple to implement such a function.
Below we will use a simple code example to introduce you to the functional method of usingjquery to realize clicking back to the top.
回到顶部特效 网页内容
返回顶部
In this code, we mainly referenced a jquery online library, and wrote some simple HTML pages and js code to judge. When the height of the scroll bar from the top is greater than 150, the setting button appears. , otherwise the button is hidden. Finally access it through the browser, the effect is as follows:
Then we drag the scroll bar down, and the button to return to the top will slowly appear, the effect is as follows:
Note:
fadeIn()The method uses the fade-in effect to display the selected element if the element is hidden . (In this example, the parameter is set to 1000 milliseconds, which means that the fade-in transition time of the selected element is 1000 milliseconds. If it is set to 0, the selected element will appear immediately.)
fadeOut()Method uses the fade out effect to hide the selected element, if the element is hidden. (Parameters are the same as above)
This article is about the introduction ofjquery to achieve the effect of returning the web page to the top. It is simple and easy to understand. I hope it will be helpful to friends in need!
If you want to know more about front-end related knowledge, you can follow PHP Chinese websitejQuery video tutorialorHTML video tutorial,CSS video tutorial,Bootstrap video tutorialand other related video tutorials, welcome everyone to refer to and learn!
The above is the detailed content of How to achieve the effect of clicking on the web page to return to the top in jquery? (Pictures + Videos). For more information, please follow other related articles on the PHP Chinese website!