-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
247 additions
and
197 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,119 +1,123 @@ | ||
/** | ||
* jQuery plugin paroller.js v1.0 | ||
* jQuery plugin paroller.js v1.3.0 | ||
* https://github.com/tgomilar/paroller.js | ||
* preview: https://tgomilar.github.io/paroller/ | ||
**/ | ||
(function (factory) { | ||
'use strict'; | ||
(function (factory) { | ||
'use strict'; | ||
|
||
if (typeof module === 'object' && typeof module.exports === 'object') { | ||
module.exports = factory(require('jquery')); | ||
} | ||
else { | ||
factory(jQuery); | ||
} | ||
})(function ($) { | ||
'use strict'; | ||
if (typeof module === 'object' && typeof module.exports === 'object') { | ||
module.exports = factory(require('jquery')); | ||
} | ||
else { | ||
factory(jQuery); | ||
} | ||
})(function ($) { | ||
'use strict'; | ||
|
||
var setDirection = { | ||
bgVertical: function (elem, bgOffset) { | ||
return elem.css({'background-position': 'center ' + -bgOffset + 'px'}); | ||
}, | ||
bgHorizontal: function (elem, bgOffset) { | ||
return elem.css({'background-position': -bgOffset + 'px' + ' center'}); | ||
}, | ||
vertical: function (elem, elemOffset) { | ||
return elem.css({ | ||
'-webkit-transform': 'translateY(' + elemOffset + 'px)', | ||
'-moz-transform': 'translateY(' + elemOffset + 'px)', | ||
'transform': 'translateY(' + elemOffset + 'px)' | ||
}); | ||
}, | ||
horizontal: function (elem, elemOffset) { | ||
return elem.css({ | ||
'-webkit-transform': 'translateX(' + elemOffset + 'px)', | ||
'-moz-transform': 'translateX(' + elemOffset + 'px)', | ||
'transform': 'translateX(' + elemOffset + 'px)' | ||
}); | ||
} | ||
}; | ||
var setDirection = { | ||
bgVertical: function (elem, bgOffset) { | ||
return elem.css({'background-position': 'center ' + -bgOffset + 'px'}); | ||
}, | ||
bgHorizontal: function (elem, bgOffset) { | ||
return elem.css({'background-position': -bgOffset + 'px' + ' center'}); | ||
}, | ||
vertical: function (elem, elemOffset) { | ||
return elem.css({ | ||
'-webkit-transform': 'translateY(' + elemOffset + 'px)', | ||
'-moz-transform': 'translateY(' + elemOffset + 'px)', | ||
'transform': 'translateY(' + elemOffset + 'px)', | ||
'transition': 'transform linear', | ||
'will-change': 'transform' | ||
}); | ||
}, | ||
horizontal: function (elem, elemOffset) { | ||
return elem.css({ | ||
'-webkit-transform': 'translateX(' + elemOffset + 'px)', | ||
'-moz-transform': 'translateX(' + elemOffset + 'px)', | ||
'transform': 'translateX(' + elemOffset + 'px)', | ||
'transition': 'transform linear', | ||
'will-change': 'transform' | ||
}); | ||
} | ||
}; | ||
|
||
$.fn.paroller = function (options) { | ||
var windowHeight = $(window).height(); | ||
var documentHeight = $(document).height(); | ||
$.fn.paroller = function (options) { | ||
var windowHeight = $(window).height(); | ||
var documentHeight = $(document).height(); | ||
|
||
// default options | ||
var options = $.extend({ | ||
factor: 0, // - to + | ||
type: 'background', // foreground | ||
direction: 'vertical' // horizontal | ||
}, options); | ||
// default options | ||
var options = $.extend({ | ||
factor: 0, // - to + | ||
type: 'background', // foreground | ||
direction: 'vertical' // horizontal | ||
}, options); | ||
|
||
return this.each(function () { | ||
var working = false; | ||
var $this = $(this); | ||
var offset = $this.offset().top; | ||
var height = $this.outerHeight(); | ||
var dataFactor = $this.data('paroller-factor'); | ||
var dataType = $this.data('paroller-type'); | ||
var dataDirection = $this.data('paroller-direction'); | ||
return this.each(function () { | ||
var working = false; | ||
var $this = $(this); | ||
var offset = $this.offset().top; | ||
var height = $this.outerHeight(); | ||
var dataFactor = $this.data('paroller-factor'); | ||
var dataType = $this.data('paroller-type'); | ||
var dataDirection = $this.data('paroller-direction'); | ||
|
||
var factor = (dataFactor) ? dataFactor : options.factor; | ||
var type = (dataType) ? dataType : options.type; | ||
var direction = (dataDirection) ? dataDirection : options.direction; | ||
var bgOffset = Math.round(offset * factor); | ||
var transform = Math.round((offset - (windowHeight / 2) + height) * factor); | ||
var factor = (dataFactor) ? dataFactor : options.factor; | ||
var type = (dataType) ? dataType : options.type; | ||
var direction = (dataDirection) ? dataDirection : options.direction; | ||
var bgOffset = Math.round(offset * factor); | ||
var transform = Math.round((offset - (windowHeight / 2) + height) * factor); | ||
|
||
if (type == 'background') { | ||
if (direction == 'vertical') { | ||
setDirection.bgVertical($this, bgOffset); | ||
} | ||
else if (direction == 'horizontal') { | ||
setDirection.bgHorizontal($this, bgOffset); | ||
} | ||
} | ||
else if (type == 'foreground') { | ||
if (direction == 'vertical') { | ||
setDirection.vertical($this, transform); | ||
} | ||
else if (direction == 'horizontal') { | ||
setDirection.horizontal($this, transform); | ||
} | ||
} | ||
if (type == 'background') { | ||
if (direction == 'vertical') { | ||
setDirection.bgVertical($this, bgOffset); | ||
} | ||
else if (direction == 'horizontal') { | ||
setDirection.bgHorizontal($this, bgOffset); | ||
} | ||
} | ||
else if (type == 'foreground') { | ||
if (direction == 'vertical') { | ||
setDirection.vertical($this, transform); | ||
} | ||
else if (direction == 'horizontal') { | ||
setDirection.horizontal($this, transform); | ||
} | ||
} | ||
|
||
var scrollAction = function () { | ||
working = false; | ||
}; | ||
var scrollAction = function () { | ||
working = false; | ||
}; | ||
|
||
$(window).on('scroll', function () { | ||
if (!working) { | ||
var scrolling = $(this).scrollTop(); | ||
$(window).on('scroll', function () { | ||
if (!working) { | ||
var scrolling = $(this).scrollTop(); | ||
documentHeight = $(document).height(); | ||
|
||
bgOffset = Math.round((offset - scrolling) * factor); | ||
transform = Math.round(((offset - (windowHeight / 2) + height) - scrolling) * factor); | ||
bgOffset = Math.round((offset - scrolling) * factor); | ||
transform = Math.round(((offset - (windowHeight / 2) + height) - scrolling) * factor); | ||
|
||
if (type == 'background') { | ||
if (direction == 'vertical') { | ||
setDirection.bgVertical($this, bgOffset); | ||
} | ||
else if (direction == 'horizontal') { | ||
setDirection.bgHorizontal($this, bgOffset); | ||
} | ||
} | ||
else if ((type == 'foreground') && (scrolling < documentHeight)) { | ||
if (direction == 'vertical') { | ||
setDirection.vertical($this, transform); | ||
} | ||
else if (direction == 'horizontal') { | ||
setDirection.horizontal($this, transform); | ||
} | ||
} | ||
if (type == 'background') { | ||
if (direction == 'vertical') { | ||
setDirection.bgVertical($this, bgOffset); | ||
} | ||
else if (direction == 'horizontal') { | ||
setDirection.bgHorizontal($this, bgOffset); | ||
} | ||
} | ||
else if ((type == 'foreground') && (scrolling <= documentHeight)) { | ||
if (direction == 'vertical') { | ||
setDirection.vertical($this, transform); | ||
} | ||
else if (direction == 'horizontal') { | ||
setDirection.horizontal($this, transform); | ||
} | ||
} | ||
|
||
window.requestAnimationFrame(scrollAction); | ||
|
||
working = true; | ||
} | ||
}).trigger('scroll'); | ||
}); | ||
}; | ||
}); | ||
window.requestAnimationFrame(scrollAction); | ||
working = true; | ||
} | ||
}).trigger('scroll'); | ||
}); | ||
}; | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.