Home > Web Front-end > JS Tutorial > jquery web page return to top effect (icon fade, self-writing)_jquery

jquery web page return to top effect (icon fade, self-writing)_jquery

WBOY
Release: 2016-05-16 16:44:16
Original
1211 people have browsed it

Well, let’s come to the development requirements. When the webpage has a lot of content, users need to have a button to quickly return to the top, instead of rolling the wheel themselves~

I originally thought it would be difficult to say, because the above requires all to be used. js to implement, which page is referenced and which page is displayed.

So, I tried to write it down, eh, I didn’t find it, it’s pretty easy to say~~

I’ll fart as soon as I can, go directly to the code, there’s a lot of farts It becomes shit~~ Well, sin, Amitabha, Amen~~

Copy code The code is as follows:

//Back to top js 
$(function(){
var $btn_top = $('');
$btn_top.css({
'display':'none',
'width':'40px',
'height':'40px',
'position':'fixed',
'right':'20px',
'bottom' :'100px',
'z-index':'999'
});
$("body").append($btn_top);
$("body").on ("click","#scrollTopBtn",function(){
$("html,body").animate({scrollTop: 0},"slow");
});
var $ btn = $("#scrollTopBtn");
if($(window).scrollTop() > 100){
$btn.fadeIn(600);
}
$(window) .scroll(function(){
if($(window).scrollTop() > 100){
$btn.fadeIn(600);
}else{
$btn.fadeOut( 600);
}
});
});

Just find the image yourself. I use the absolute path "css/web/images/" scrollTop.png”

Just change the size directly on the fifth and sixth lines, thus avoiding the need to add cat tags to the page~~(>^ω^<)Meow~~~

Save it as a js file and quote it directly. Use it wherever it hurts. Who knows who uses it~~~
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template