1 (function($) {
2
3     $.fn.backTop = function(options) {
4         
5         
var backBtn = this;
6         
7         
var settings = $.extend({
8             
'position' : 400,
9             
'speed' : 500,
10             
'color' : 'white',
11             
'theme' : '' // red, green, white, custom
12         }, options);
13         
14         
//Settings
15         
16         
var position = settings['position'];
17         
var speed = settings['speed'];
18         
var color = settings['color'];
19         
var theme = settings['theme'];
20         
21         
if(theme == 'white'){
22             backBtn.addClass(
'white');
23         }
else if(theme == 'red'){
24             backBtn.addClass(
'red');
25         }
else if(theme == 'green'){
26             backBtn.addClass(
'green');
27         }
else if(theme == 'custom'){
28             backBtn.addClass(
'custom');
29         }
else{
30             backBtn.addClass(
'black');
31         }
32         
33         backBtn.css({
34             
'right' : 24,
35             
'bottom' : 24,
36             
'position' : 'fixed'
37         });
38         
39         $(document).scroll(function(){
40             
var pos = $(window).scrollTop();
41 // console.log(pos);

42             
43             
if(pos >= position){
44                 backBtn.fadeIn(speed);
45             }
else{
46                 backBtn.fadeOut(speed);
47             }
48         });
49         
50         backBtn.click(function(){
51             $(
"html, body").animate({
52                 scrollTop:
0
53             },
54             {
55                 duration:
1200
56             });
57         });
58
59     }
60
61 }(jQuery));


Gõ tìm kiếm nhanh...