1.$.proxy (Fn,context)
2.$ (window). scrolltop ()
3.requirejs:
Define a module
Define ([],function () {
Write a constructor + prototype
return {
XXX: Constructors
}
});
When used, var x = new X.xxx ({xxxx})
define ([' jquery '],function($) { functionScrollTo1 (opts) { This. opts =$.extend ({}, Scrollto1.defaults, opts); This. $el = $ (' html,body '); } ScrollTo1.prototype.move=function() { if($ (window). scrolltop ()! = This. Opts.dest) { if(! This. $el. Is (': Animated ')){ This. $el. Animate ({scrolltop: This. Opts.dest}, This. Opts.speed); } } }; ScrollTo1.prototype.go=function() { This. $el. ScrollTop ( This. Opts.dest)} Scrollto1.defaults={dest:0, Speed:800 } return{scrollto:scrollto1}});
//This is the entry file .require.config ({paths:{jquery:' Jquery-2.1.4.min '}}); Require ([' jquery ', ' Scrollto '],function($,scroll) {varS =NewScroll. ScrollTo ({' dest ': 20}); $(' #backtop '). On (' click ', $.proxy (s.move,s)); //$ (window). On (' scroll ', function () { //checkposition ($ (window). Height ()); // }); //checkposition ($ (window). Height ()); //function Checkposition (POS) { //if ($ (window). scrolltop () > pos) { //$ (' #backtop '). FadeIn (); //}else{ //$ (' #backtop '). FadeOut (); // } // }});
$.fn.extend ({ backtop:function(opts) { returnthis . Each (function() { new backtop (this, opts) }) } })
Side Development Tools 4