|
@@ -1,15 +1,17 @@
|
|
|
/**
|
|
|
jquery-inertiaScroll
|
|
|
|
|
|
-Copyright(c) 2016 Go Nishiduka
|
|
|
+Copyright(c) 2017 Go Nishiduka
|
|
|
|
|
|
This software is released under the MIT License.
|
|
|
http://opensource.org/licenses/mit-license.php
|
|
|
|
|
|
-Last Update: 2017-5-24
|
|
|
-Version:1.0.1
|
|
|
+Last Update: 2017-10-23
|
|
|
+Version:1.1.1
|
|
|
*/
|
|
|
|
|
|
+'use strict';
|
|
|
+
|
|
|
(function($){
|
|
|
$.fn.inertiaScroll = function(options){
|
|
|
|
|
@@ -18,7 +20,7 @@ Version:1.0.1
|
|
|
//////////////////////////////////////////////////
|
|
|
|
|
|
var settings = $.extend({
|
|
|
- parent: "",
|
|
|
+ parent: '',
|
|
|
childDelta1: 0.02,
|
|
|
childDelta2: 0.1,
|
|
|
parentDelta: 0.08
|
|
@@ -35,7 +37,7 @@ Version:1.0.1
|
|
|
var $child = this;
|
|
|
|
|
|
//////////////////////////////////////////////////
|
|
|
- // inertiaScroll childClass
|
|
|
+ // inertiaScroll childClass
|
|
|
//////////////////////////////////////////////////
|
|
|
|
|
|
var ChildBox = function(elm, offset, speed, margin){
|
|
@@ -43,34 +45,34 @@ Version:1.0.1
|
|
|
this.offset = offset !== undefined ? offset : 0;
|
|
|
this.speed = speed !== undefined ? speed : 1;
|
|
|
this.margin = margin !== undefined ? margin : 0;
|
|
|
- }
|
|
|
+ };
|
|
|
ChildBox.prototype.update = function(windowOffset,offsetBottom){
|
|
|
- this.offset += (windowOffset * settings.childDelta1 * Number(this.speed) - this.offset) * settings.childDelta2;
|
|
|
- this.elm.css({transform:'translate3d(' + 0 + ',' + ( Number(this.margin) - Number(this.offset) ) + 'px ,' + 0 +')'});
|
|
|
- }
|
|
|
+ this.offset += (windowOffset * settings.childDelta1 * Number(this.speed) - this.offset) * settings.childDelta2;
|
|
|
+ this.elm.css({transform:'translate3d(' + 0 + ',' + ( Number(this.margin) - Number(this.offset) ) + 'px ,' + 0 +')'});
|
|
|
+ };
|
|
|
|
|
|
//////////////////////////////////////////////////
|
|
|
- // inertiaScroll parentClass
|
|
|
+ // inertiaScroll parentClass
|
|
|
//////////////////////////////////////////////////
|
|
|
|
|
|
var ParentBox = function(elm, offset, speed, margin){
|
|
|
- ChildBox.apply(this,arguments);
|
|
|
- }
|
|
|
+ ChildBox.apply(this,arguments);
|
|
|
+ };
|
|
|
ParentBox.prototype = Object.create(ChildBox.prototype,{
|
|
|
constructor:{
|
|
|
value: ParentBox
|
|
|
}
|
|
|
});
|
|
|
ParentBox.prototype.update = function(windowOffset){
|
|
|
- this.offset += (windowOffset - this.offset) * settings.parentDelta;
|
|
|
- this.elm.css({transform:'translate3d(' + 0 + ',' + -this.offset + 'px ,' + 0 +')'});
|
|
|
- }
|
|
|
+ this.offset += (windowOffset - this.offset) * settings.parentDelta;
|
|
|
+ this.elm.css({transform:'translate3d(' + 0 + ',' + (-this.offset) + 'px ,' + 0 + ')'});
|
|
|
+ };
|
|
|
ParentBox.prototype.setcss = function(){
|
|
|
this.elm.css({
|
|
|
'width':'100%',
|
|
|
'position':'fixed'
|
|
|
});
|
|
|
- }
|
|
|
+ };
|
|
|
|
|
|
//////////////////////////////////////////////////
|
|
|
// make Object
|
|
@@ -79,11 +81,11 @@ Version:1.0.1
|
|
|
var Boxes = function(){
|
|
|
this.ChildBox = [];
|
|
|
this.ChildBoxLength = 0;
|
|
|
- this.ParentBox = "";
|
|
|
+ this.ParentBox = '';
|
|
|
this.windowHeight = 0;
|
|
|
- }
|
|
|
+ };
|
|
|
Boxes.prototype = {
|
|
|
- init:function(){
|
|
|
+ init:function(){
|
|
|
this.createElm($child,$parent);
|
|
|
this.loop();
|
|
|
},
|
|
@@ -93,8 +95,8 @@ Version:1.0.1
|
|
|
this.boxArrayLength = child.length;
|
|
|
for (var i = 0; i < this.boxArrayLength; i++) {
|
|
|
var e = child.eq(i);
|
|
|
- var speed = e.data("speed");
|
|
|
- var margin = e.data("margin");
|
|
|
+ var speed = e.data('speed');
|
|
|
+ var margin = e.data('margin');
|
|
|
this.ChildBox.push(new ChildBox(e,0,speed,margin));
|
|
|
}
|
|
|
},
|
|
@@ -110,7 +112,7 @@ Version:1.0.1
|
|
|
this.smoothScroll();
|
|
|
window.requestAnimationFrame(this.loop.bind(this));
|
|
|
}
|
|
|
- }
|
|
|
+ };
|
|
|
|
|
|
//////////////////////////////////////////////////
|
|
|
// Done
|