Today I am going to show you how you can create a smooth animated scroll to top with jQuery. It is very easy and we need to code only couple of lines to implement this. We need to code for
Let's go to implement it..
#back-top is the scroll top button. #top is added to the body tag for no JavaScript fallback.
CSS Part
#back-top position is fixed 30px bottom and 100px right, top.png as background and transition is 1 second.
- Hide button on load
- If user scroll more than 400px then show the button
- If user go to top then hide the button
- Scroll to top with Animate method
Let's go to implement it..
Download Source
Live Demo
HTML Part#back-top is the scroll top button. #top is added to the body tag for no JavaScript fallback.
<html> <head> <title>Scroll to top</title> <head> <body id="top"> <div class="wrap"> <!--main div--> <!-- contents here --> </div> <div id="back-top"><!-- scroll top button --> <a href="#top"><span></span>Back to Top</a> </div> </body> </html>
CSS Part
#back-top position is fixed 30px bottom and 100px right, top.png as background and transition is 1 second.
/* Back to top button */ #back-top { position: fixed; bottom: 30px; right: 100px; } #back-top a { width: 64px; display: block; text-align: center; font: 11px/100% Arial, Helvetica, sans-serif; text-transform: uppercase; text-decoration: none; color: #bbb; /* background color transition */ -webkit-transition: 1s; -moz-transition: 1s; transition: 1s; } #back-top a:hover { color: #000; } /* arrow icon (span tag) */ #back-top span { width: 64px; height: 64px; display: block; margin-bottom: 7px; background: #ddd url(top.png) no-repeat center center; /* rounded corners */ -webkit-border-radius: 15px; -moz-border-radius: 15px; border-radius: 15px; /* background color transition */ -webkit-transition: 1s; -moz-transition: 1s; transition: 1s; } #back-top a:hover span { background-color: #fff; } #back{ font-weight: bold; font-size: 22px; padding:10px; border: 2px solid #333; border-radius: 29px; }jQuery Part
$(function() { // cache scroll to top button var b = $('#back-top'); // Hide scroll top button b.hide(); // FadeIn or FadeOut scroll to top button on scroll $(window).on('scroll', function(){ // if you scroll more then 400px then fadein goto top button if ($(this).scrollTop() > 400) { b.fadeIn(); // otherwise fadeout button } else { b.fadeOut(); } }); // Animated scroll to top b.on('click', function(){ $('html,body').animate({ scrollTop: 0 }, 500 ); return false; }); });
dịch vụ kế toán thuế tại quận gò vấp
ReplyDeletedịch vụ kế toán thuế tại quận 2
dịch vụ kế toán thuế tại quận 1
học kế toán thực hành cấp tốc
học kế toán thực hành cấp tốc
học kế toán thực hành tại cầu giấy
học kế toán thực hành tại cầu giấy
học kế toán thực hành tại thanh xuân
học kế toán thực hành tại thanh xuân
khóa học kế toán xây dựng
khóa học kế toán xây dựng
khóa học kế toán xây dựng
khóa học kế toán toán dành cho giám đốc và nhà quản lý
dịch vụ thành lập doanh nghiệp công ty trọn gói
dịch vụ thành lập doanh nghiệp công ty tại hải phòng
dịch vụ tạm ngừng giải thể doanh nghiệp
dich vu ke toan thue
dich vu lam bao cao tai chinh
Great and helpful tutorial. I am using this , This is also simple
ReplyDelete$(document).ready(function(e) {
var a = 400,
t = 1200,
l = 700,
s = e(".scrool-top");
e(window).scroll(function() {
e(this).scrollTop() > a ? s.addClass("scrool-is-visible") : s.removeClass("scrool-is-visible scrool-fade-out"), e(this).scrollTop() > t && s.addClass("scrool-fade-out")
}), s.on("click", function(a) {
a.preventDefault(), e("body,html").animate({
scrollTop: 0
}, l)
})
})
Animated Scroll To Top Using jQuery
I have read your blog its very attractive and impressive. I like it your blog.
ReplyDeletePHP Training in chennai | PHP Training Course
PHP Training in chennai | Online PHP Course
The share your really gives us excitement. Thanks for your sharing. If you feel tired at work or study try to participate in our games to bring the most exciting feeling. Thank you!
ReplyDeletehotmail sign in | red ball game
The blog or and best that is extremely useful to keep I can share the ideas of the future as this is really what I was looking for, I am very comfortable and pleased to come here. Thank you very much.
ReplyDeleteanimal jam | five nights at freddy's | hotmail login
The information you share is very useful. It is closely related to my work and has helped me grow. Thank you!
ReplyDeletecolour switch
Himachal Pradesh University BA Part 2 Result
ReplyDeleteHimachal Pradesh University BA Part 3 Result