Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var Scrollify = function(){
- this.$elements = $('.js-scrollify');
- this.$win = $(window);
- this.winST = 0;
- this.onScroll = function() {
- var _this = this;
- _this
- .$elements
- .each(function() {
- var $this = $(this);
- var value = $this.data('scrollify-value');
- var elementOT = $this.offset().top + _this.winST;
- var elementHeight = $this.outerHeight();
- var elementOB = elementOT + $this.outerHeight();
- var winHeight = _this.$win.outerHeight();
- var winSB = _this.winST + winHeight;
- if (winSB > elementOT && _this.winST < elementOB) {
- var totalScroll = winHeight + elementHeight;
- var currentScroll = _this.winST - (elementOT - winHeight);
- switch($this.data('scrollify-animate')) {
- case 'translatey':
- $this.css({
- 'transform': 'translate(0px, -' + (value * (currentScroll / totalScroll)) + 'px)'
- });
- break;
- case 'translatex':
- $this.css({
- 'transform': 'translate(' + (value * (currentScroll / totalScroll)) + 'px, 0px)'
- });
- break;
- case 'opacity':
- $this.css({
- 'opacity': value * (currentScroll / totalScroll)
- });
- break;
- case 'scale':
- $this.css({
- 'transform': 'scale(' + (value * (currentScroll / totalScroll))+ ')'
- });
- break;
- }
- }
- });
- }
- };
Add Comment
Please, Sign In to add comment