开源软件名称(OpenSource Name):dixonandmoe/rellax开源软件地址(OpenSource Url):https://github.com/dixonandmoe/rellax开源编程语言(OpenSource Language):HTML 71.6%开源软件介绍(OpenSource Introduction):RELLAXRellax is a buttery smooth, super lightweight, vanilla javascript parallax library. Update: Rellax now works on mobile (v1.0.0). Getting StartedUsing npm
Using yarn
CDN
Download Locallyif you're old school like us download and insert <div class="rellax">
I’m that default chill speed of "-2"
</div>
<div class="rellax" data-rellax-speed="7">
I’m super fast!!
</div>
<div class="rellax" data-rellax-speed="-4">
I’m extra slow and smooth
</div>
<script src="https://cdn.jsdelivr.net/gh/dixonandmoe/rellax@master/rellax.min.js"></script>
<script>
// Accepts any class name
var rellax = new Rellax('.rellax');
</script> <script>
// Also can pass in optional settings block
var rellax = new Rellax('.rellax', {
speed: -2,
center: false,
wrapper: null,
round: true,
vertical: true,
horizontal: false
});
</script> FeaturesSpeedUse the Responsive SpeedUse responsive speed attributes for breakpoint levels that require a different speed. Defaults to the <div class="rellax" data-rellax-speed="7" data-rellax-xs-speed="-5" data-rellax-mobile-speed="3" data-rellax-tablet-speed="-8" data-rellax-desktop-speed="1">
I parallax at all different speeds depending on your screen width.
</div> Pass an array of breakpoints. Each breakpoint value represents the resolution for mobile, tablet, desktop respectively. Checkout the responsiveness of the <script>
// This is the default setting
var rellax = new Rellax('.rellax', {
breakpoints: [576, 768, 1201]
});
</script> CenteringAfter some fantastic work from @p-realinho, we just released the ability to center parallax elements in your viewport! We'll be building a nice demo website, but for now check out the tests folder for several examples of how it works. There's two ways to implement centering, either on specific elements or as a global option.
<div class="rellax" data-rellax-percentage="0.5">
I’m that default chill speed of "-2" and "centered"
</div>
<div class="rellax" data-rellax-speed="7" data-rellax-percentage="0.5">
I’m super fast!! And super centered!!
</div>
<div class="rellax" data-rellax-speed="-4" data-rellax-percentage="0.5">
I’m extra slow and smooth, and hella centered.
</div>
<script>
// Center all the things!
var rellax = new Rellax('.rellax', {
center: true
});
</script> Z-indexIf you want to sort your elements properly in the Z space, you can use the data-rellax-zindex property <div class="rellax">
I’m that default chill speed of "-2" and default z-index of 0
</div>
<div class="rellax" data-rellax-speed="7" data-rellax-zindex="5">
I’m super fast!! And on top of the previous element, I'm z-index 5!!
</div> Horizontal ParallaxHorizontal parallax is disabled by default. You can enable it by passing <script>
// Adding horizantal parallax scrolling
var rellax = new Rellax('.rellax', {
// Activate horizantal scrolling
// Turned off by default
horizontal: true
//Deactivate vertical scrolling
vertical: false
});
</script> Custom WrapperBy default, the position of parallax elements is determined via the scroll position of the body. Passing in the <script>
// Set wrapper to .custom-element instead of the body
var rellax = new Rellax('.rellax', {
wrapper: '.custom-element'
});
</script> Refresh<script>
// Start Rellax
var rellax = new Rellax('.rellax');
// Destroy and create again parallax with previous settings
rellax.refresh();
</script> Destroy<script>
// Start Rellax
var rellax = new Rellax('.rellax');
// End Rellax and reset parallax elements to their original positions
rellax.destroy();
</script> Callback<script>
// Start Rellax
var rellax = new Rellax('.rellax-blur-card', {
callback: function(positions) {
// callback every position change
console.log(positions);
}
});
</script> Target nodeInstead of using a className you can use a node, handy when using React and you want to use <div ref={ref => { this.rellaxRef = ref }}>
I’m that default chill speed of "-2"
</div>
var rellax = new Rellax(this.rellaxRef) In the WildIf you're using Rellax in production, we'd love to list you here! Let us know: moe@dixonandmoe.com
DevelopmentIn the spirit of lightweight javascript, the build processes (thus far) is lightweight also.
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论