码迷,mamicode.com
首页 > 其他好文 > 详细

侧边开发工具4

时间:2015-09-28 22:21:41      阅读:309      评论:0      收藏:0      [点我收藏+]

标签:

1.$.proxy(fn,context)

2.$(window).scrollTop()

3.requirejs:

定义一个模块

define([],function(){

 写一个构造函数+原型

 

return {

xxx:构造函数

}

});

在使用的时候,var x = new x.xxx({xxxx})

define([‘jquery‘], function($) {
  function ScrollTo1(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
  }
});
//这是入口文件
require.config({
  paths:{
    jquery:‘jquery-2.1.4.min‘
  }
});
require([‘jquery‘,‘scrollto‘],function($,scroll){
  var S = new scroll.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){
     return  this.each(function(){
        new BackTop(this,opts)
      })
      
    }
  })

 

侧边开发工具4

标签:

原文地址:http://www.cnblogs.com/yangxiaomie/p/4845089.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!