(Simple) Parallax with background-position and scroll reveal
How do I make an (simple) parallax with background-position and scroll reveal?
Just a pen to show a friend how to achieve this effect; Need to add more functionality;Some of the variables are not used at the moment, but will need them later, so I just left them. . What is a (simple) parallax with background-position and scroll reveal? How do you make a (simple) parallax with background-position and scroll reveal? This script and codes were developed by Chrysto on 16 July 2022, Saturday.
(Simple) Parallax with background-position and scroll reveal - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>(Simple) Parallax with background-position and scroll reveal</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css"> <style> /* NOTE: The styles were added inline because Prefixfree needs access to your styles and they must be inlined if they are on local disk! */ .holder { min-height: 2500px;
}
section { min-height: 300px; padding-top: 70px; padding-bottom: 70px;
}
section:nth-child(0) { background-color: rgba(255, 0, 0, 0.3);
}
section:nth-child(1) { background-color: rgba(0, 128, 0, 0.3);
}
section:nth-child(2) { background-color: rgba(255, 255, 0, 0.3);
}
section:nth-child(3) { background-color: rgba(0, 0, 255, 0.3);
}
section:nth-child(4) { background-color: rgba(0, 0, 0, 0.3);
}
section:nth-child(5) { background-color: rgba(0, 255, 255, 0.3);
}
section:nth-child(6) { background-color: rgba(255, 165, 0, 0.3);
}
section:nth-child(7) { background-color: rgba(255, 192, 203, 0.3);
}
section:nth-child(8) { background-color: rgba(128, 128, 128, 0.3);
}
section:nth-child(9) { background-color: rgba(0, 0, 139, 0.3);
}
section:nth-child(10) { background-color: rgba(0, 128, 0, 0.3);
}
.parallax { position: relative; background-attachment: fixed; background-repeat: no-repeat; background-position: 50% 50%;
}
.parallax-1 { min-height: 500px; background-image: url("https://placekitten.com/g/1900/1280");
}
.parallax-2 { background-image: url("https://placekitten.com/g/1900/1230");
}
.parallax-3 { background-image: url("https://placekitten.com/g/1900/1300");
}
.scrollreveal { font-size: 60px; color: white; text-align: center; width: 50%; margin: 0 auto; padding: 30px; background-color: rgba(0, 0, 0, 0.2); -webkit-transition: all .5s; transition: all .5s; /* Hide on default*/ opacity: 0; }
.scrollreveal-2 { -webkit-transition-duration: 2s; transition-duration: 2s; -webkit-transform: scale(0); -ms-transform: scale(0); transform: scale(0); }
.scrollreveal-2.js-revealed { opacity: 1; -webkit-transform: scale(1); -ms-transform: scale(1); transform: scale(1); }
/* Will be added when item is fully visible, and removed when it's fully out of viewport */
.js-reveal { opacity: 1; }
/* Will be added the first time item is fully visible */
.js-revealed { background-color: rgba(0, 0, 0, 0.7); }
/*# sourceMappingURL=style.css.map */ </style> <script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
</head>
<body> <div class="holder"> <section></section> <section class="parallax parallax-1" data-parallax="100"></section> <section></section> <section> <div class="scrollreveal scrollreveal-1"> Show when enter Viewport </div> </section> <section></section> <section class="parallax parallax-2" data-parallax="200"> <div class="scrollreveal scrollreveal-2"> Only on first reveal </div> </section> <section></section> <section></section> <section class="parallax parallax-3" data-parallax="50"></section> <section></section>
</div> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
(Simple) Parallax with background-position and scroll reveal - Script Codes CSS Codes
.holder { min-height: 2500px;
}
section { min-height: 300px; padding-top: 70px; padding-bottom: 70px;
}
section:nth-child(0) { background-color: rgba(255, 0, 0, 0.3);
}
section:nth-child(1) { background-color: rgba(0, 128, 0, 0.3);
}
section:nth-child(2) { background-color: rgba(255, 255, 0, 0.3);
}
section:nth-child(3) { background-color: rgba(0, 0, 255, 0.3);
}
section:nth-child(4) { background-color: rgba(0, 0, 0, 0.3);
}
section:nth-child(5) { background-color: rgba(0, 255, 255, 0.3);
}
section:nth-child(6) { background-color: rgba(255, 165, 0, 0.3);
}
section:nth-child(7) { background-color: rgba(255, 192, 203, 0.3);
}
section:nth-child(8) { background-color: rgba(128, 128, 128, 0.3);
}
section:nth-child(9) { background-color: rgba(0, 0, 139, 0.3);
}
section:nth-child(10) { background-color: rgba(0, 128, 0, 0.3);
}
.parallax { position: relative; background-attachment: fixed; background-repeat: no-repeat; background-position: 50% 50%;
}
.parallax-1 { min-height: 500px; background-image: url("https://placekitten.com/g/1900/1280");
}
.parallax-2 { background-image: url("https://placekitten.com/g/1900/1230");
}
.parallax-3 { background-image: url("https://placekitten.com/g/1900/1300");
}
.scrollreveal { font-size: 60px; color: white; text-align: center; width: 50%; margin: 0 auto; padding: 30px; background-color: rgba(0, 0, 0, 0.2); -webkit-transition: all .5s; transition: all .5s; /* Hide on default*/ opacity: 0; }
.scrollreveal-2 { -webkit-transition-duration: 2s; transition-duration: 2s; -webkit-transform: scale(0); -ms-transform: scale(0); transform: scale(0); }
.scrollreveal-2.js-revealed { opacity: 1; -webkit-transform: scale(1); -ms-transform: scale(1); transform: scale(1); }
/* Will be added when item is fully visible, and removed when it's fully out of viewport */
.js-reveal { opacity: 1; }
/* Will be added the first time item is fully visible */
.js-revealed { background-color: rgba(0, 0, 0, 0.7); }
/*# sourceMappingURL=style.css.map */
(Simple) Parallax with background-position and scroll reveal - Script Codes JS Codes
;
(function($, window, document, undefined) { var defaults = { viewportSelector: null, //Effect could be parallax or scrollReveal effectType: 'parallax', //Parallax options parallaxMaxOffset: 100, //Scroll Reveal options //Added when item is fully visible, removed when it's fully out of viewport scrollRevealedClass: 'js-reveal', //Added the first time the item is revealed, it's not remove when the item is hidden scrollFirstRevealClass: 'js-revealed', autoEnable: true, // debug: false }; function ScrollEffects(element, options) { this.settings = $.extend({}, defaults, options); this.$window = $(window); this.$viewport = this.settings.viewportSelector ? $(this.settings.viewportSelector) : this.$window; this.$elements = $(element); this.scrollables = []; this.isEnabled = false; this.wpWidth = this.$viewport.width(); this.wpHeight = this.$viewport.height(); this.scrollTop = 0; this.init(); } ScrollEffects.TYPE = { PARALLAX: 'parallax', SCROLLREVEAL: 'scrollReveal' }; ScrollEffects.prototype = { init: function() { this.createScrollables(); if (this.settings.autoEnable) { this.enable(); } }, createScrollables: function() { if (this.settings.debug) { this.$debug = $('<div />').css({ 'z-index': 1000, 'position': 'fixed', 'top': '10px', 'left': '20px', 'color': 'white', 'background-color': 'rgba(0,0,0,.3)', 'padding': '10px 5px', 'border-radius': '3px' }).text('debug').appendTo($('body')); } for (var i = 0, j = this.$elements.length; i < j; i++) { var $element = this.$elements.eq(i), scrollable = { $element: $element }; //Parallax if (this.settings.effectType == ScrollEffects.TYPE.PARALLAX) { scrollable.maxOffset = $.isNumeric($element.data('parallax')) ? parseInt($element.data('parallax')) : this.settings.parallaxMaxOffset; } //ScrollReveal if (this.settings.effectType == ScrollEffects.TYPE.SCROLLREVEAL) { scrollable.isFirstReveal = true; scrollable.isRevealed = false; } //ScrollReveal items this.scrollables.push(scrollable); } }, addEvents: function() { this.resetScrollables(); this.$window.on('resize', $.proxy(this.onResize, this)); this.$window.on('scroll', $.proxy(this.onScroll, this)); this.$window.trigger('resize').trigger('scroll'); }, resetScrollables: function() { if (this.settings.effectType == ScrollEffects.TYPE.PARALLAX) {} if (this.settings.effectType == ScrollEffects.TYPE.SCROLLREVEAL) { for (var i = 0, j = this.scrollables.length; i < j; i++) { var scrollable = this.scrollables[i]; scrollable.$element.removeClass(this.settings.scrollRevealedClass); scrollable.$element.removeClass(this.settings.scrollFirstRevealClass); scrollable.isFirstReveal = true; scrollable.isRevealed = false; } } }, onScroll: function() { this.scrollTop = this.$window.scrollTop(); for (var i = 0, j = this.scrollables.length; i < j; i++) { var scrollable = this.scrollables[i], scrollData = this.getScrollData(scrollable.$element); if (this.settings.effectType == ScrollEffects.TYPE.PARALLAX) { this.processParallaxItem(scrollable, scrollData); } if (this.settings.effectType == ScrollEffects.TYPE.SCROLLREVEAL) { this.processScrollRevealItem(scrollable, scrollData); } } }, processParallaxItem: function(_scrollable, _scrollData) { if (_scrollData.isVisible) { var offset = this.percentToRange(_scrollData.percentEntered, -_scrollable.maxOffset, _scrollable.maxOffset); _scrollable.$element.css({ 'background-position': '50% ' + parseInt(offset) + 'px' }); } }, processScrollRevealItem: function(_scrollable, _scrollData) { if (!_scrollable.isRevealed && _scrollData.isFullyEntered) { _scrollable.$element.addClass(this.settings.scrollRevealedClass); if (_scrollable.isFirstReveal) { _scrollable.isFirstReveal = false; _scrollable.$element.addClass(this.settings.scrollFirstRevealClass); } _scrollable.isRevealed = true; } if (_scrollable.isRevealed && _scrollData.isFullyExited) { _scrollable.isRevealed = false; _scrollable.$element.removeClass(this.settings.scrollRevealedClass); } }, onResize: function() { this.wpWidth = this.$viewport.width(); this.wpHeight = this.$viewport.height(); }, //-------------------------------------------------------------- // Return percent from 0 to 1 // 0.01 when element is almost at the top // 0.99 when just entered from bottom //-------------------------------------------------------------- getScrollData: function(_$element) { var viewPortData = { isVisible: false, isFullyEntered: false, isFullyExited: true, percentEntered: 0 }; var elementHeight = _$element.outerHeight(), boundRect = _$element.get(0).getBoundingClientRect(), elementTop = boundRect.top, elementBottom = boundRect.bottom; if (elementTop >= -elementHeight && elementBottom <= (this.wpHeight + elementHeight)) { viewPortData.isVisible = true; viewPortData.isFullyEntered = elementTop >= 0 && elementBottom <= this.wpHeight; viewPortData.percentEntered = this.rangeToPercent(elementTop, -elementHeight, this.wpHeight); viewPortData.isFullyExited = viewPortData.percentEntered == 0; } return viewPortData; }, enable: function() { if (!this.isEnabled) { this.isEnabled = true; this.resetScrollables(); this.addEvents(); } }, disable: function(_normalize) { if (this.isEnabled) { this.isEnabled = false; this.$window.off('scroll', $.proxy(this.onScroll, this)); this.$window.off('resize', $.proxy(this.onResize, this)); if (_normalize) { if (this.settings.effectType == ScrollEffects.TYPE.PARALLAX) { this.$elements.css({ 'background-position': '50% 50%' }); } else if (this.settings.effectType == ScrollEffects.TYPE.SCROLLREVEAL) { for (var i = 0, j = this.scrollables.length; i < j; i++) { var scrollable = this.scrollables[i]; scrollable.$element.addClass(this.settings.scrollRevealedClass); scrollable.$element.addClass(this.settings.scrollFirstRevealClass); } } } } }, //-------------------------------------------------------------- // UTILS //-------------------------------------------------------------- rangeToPercent: function(_number, _min, _max) { return ((_number - _min) / (_max - _min)); }, percentToRange: function(_percent, _min, _max) { return ((_max - _min) * _percent + _min); } }; window.ScrollEffects = ScrollEffects;
})(jQuery, window, document);
//
$(function() { var parallax = new ScrollEffects('.parallax', { effectType: 'parallax' }); var scrollShow = new ScrollEffects('.scrollreveal', { effectType: 'scrollReveal' }); var $window = $(window); $window.on('resize', function() { if ($window.width() >= 900) { parallax.enable(); scrollShow.enable(); } else { parallax.disable(true); scrollShow.disable(true); } }).trigger('resize');
});
Developer | Chrysto |
Username | bassta |
Uploaded | July 16, 2022 |
Rating | 3 |
Size | 4,927 Kb |
Views | 68,816 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Smooth scroll | 4,915 Kb |
Fullscreen slides with TweenLite, CSSPlugin and ScrollToPlugin | 4,226 Kb |
TweenLite staggerTo | 2,495 Kb |
Page Header animation | 2,828 Kb |
Lastik menu | 2,257 Kb |
Footer concept | 2,210 Kb |
Fullscreen Parallax | 3,313 Kb |
Click outside element | 1,993 Kb |
Medium.com style header effect | 2,828 Kb |
Single page website | 2,688 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Pure CSS albums gallery | Renaudtertrais | 2,978 Kb |
CSS3 Animated buttons | Cguillou | 3,737 Kb |
SVG Transform vs CSS Transform | AmeliaBR | 4,175 Kb |
Slides-07-1 POSITION | Exhtml | 1,909 Kb |
Email Marketing Mock | Kristenzirkler | 8,224 Kb |
ABVI Menu Discarded | Overdrivemachines | 3,607 Kb |
RWD Conversion Practice | Jxqr97 | 2,743 Kb |
A Pen by Jim Savage | Madebyjam | 2,418 Kb |
Flying Bee | Pwsm50 | 3,711 Kb |
Pure CSS Torch Light | Juliendargelos | 2,727 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!