console
function Scroll(up, down) {
if (window.addEventListener)
window.addEventListener('DOMMouseScroll', wheel, false);
window.onmousewheel = document.onmousewheel = wheel;
function wheel(event) {
var delta = 0;
if (!event)
event = window.event;
if (event.wheelDelta) {
delta = event.wheelDelta / 120;
if (window.opera)
delta = -delta;
}
else if (event.detail) {
delta = -event.detail / 3;
}
if (delta)
handle(delta);
}
function handle(delta) {
if (delta < 0) {
down(delta);
}
else {
up(delta);
}
}
}
function throttle(method, context, delay) {
var wait = false;
return function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
if (!wait) {
method.apply(context, args);
wait = true;
setTimeout(function () {
wait = false;
}, delay);
}
};
}
{ }
var FullScroll = (function () {
function FullScroll(config) {
var _this = this;
this.width = 0;
this.height = 0;
this.el = null;
this.current = 0;
this.pages = 0;
this.init(config);
this.regishterEvent(function (delta) {
_this.scrollTo(--_this.current);
}, function (delta) {
_this.scrollTo(++_this.current);
});
}
FullScroll.prototype.init = function (config) {
document.body.style.overflow = "hidden";
this.width = document.documentElement.clientWidth;
this.height = document.documentElement.clientHeight;
this.el = document.querySelector(config.el);
this.el.style.height = this.height + "px";
this.el.style.transition = "transform .5s";
var child = this.el.querySelectorAll(".block");
child.forEach(element=>{
element.style.height = "100%";
element.style.width = "100%";
})
this.pages = child.length;
};
FullScroll.prototype.regishterEvent = function (up, down) {
var tup = throttle(up, this, 1000);
var tdown = throttle(down, this, 1000);
Scroll(tup, tdown);
};
FullScroll.prototype.scrollTo = function (num) {
if (num >= this.pages)
num = this.pages-1;
if (num < 0)
num = 0;
this.current = num;
this.el.style.transform = "translateY(-" + this.height * this.current + "px)";
};
return FullScroll;
}());
setTimeout(function () {
new FullScroll({
el: ".box"
});
}, 2000);
<div class="box">
<div class="block red"></div>
<div class="block green"></div>
<div class="block yellow"></div>
</div>
* {
margin: 0;
padding: 0;
}
.red {
background-color: red;
}
.green {
background-color: green;
}
.yellow {
background-color: yellow;
}
.block{
width: 100%;
height: 100%;
}