cartodb/lib/assets/javascripts/dashboard/helpers/scroll-tofixed-view.js
2020-06-15 10:58:47 +08:00

44 lines
920 B
JavaScript

var $ = require('jquery');
var CoreView = require('backbone/core-view');
var checkAndBuildOpts = require('builder/helpers/required-opts');
var REQUIRED_OPTS = [
'el'
];
module.exports = CoreView.extend({
events: {
'click .js-foo': '_fooHandler'
},
initialize: function (opts) {
checkAndBuildOpts(opts, REQUIRED_OPTS, this);
this._onWindowScroll = this._onWindowScroll.bind(this);
this._topBoundary = this.$el.offset().top;
this._initBinds();
},
_initBinds: function () {
this._bindScroll();
},
_onWindowScroll: function () {
this.$el.toggleClass('is-fixed', $(window).scrollTop() > this._topBoundary);
},
_unbindScroll: function () {
$(window).unbind('scroll', this._onWindowScroll);
},
_bindScroll: function () {
this._unbindScroll();
$(window).bind('scroll', this._onWindowScroll);
},
clean: function () {
this._unbindScroll();
}
});