Comments (4)
Hi @BHWD, what you're asking for isn't supported natively by the library, but I think you can achieve something close with a little bit of custom code:
<div id="slidr-div" style="dislay: block">
<div data-slidr="one" data-delay="1000">apple</div>
<div data-slidr="two" data-delay="2000">banana</div>
<div data-slidr="three" data-delay="3000">coconut</div>
</div>
// The after transition callback which will handle the randomness
let afterCallback = (e) => {
// Retrieve the delay on the slide
let delay = e.in.el.getAttribute('data-delay');
// Wait for the delay, then trigger the next slide
setTimeout(() => {
// 50% chance to slide either direction
s.slide(!!Math.round(Math.random()) ? 'left' : 'right');
}, delay);
};
// Store a reference to the slidr.
// Create three horizontal slides in a loopback.
let s = slidr.create('slidr-div', {
after: afterCallback.bind(this)
}).add('h', ['one', 'two', 'three', 'one']);
// Now start the slidr
s.start();
// Trigger the first slide to kick off the slides
setTimeout(() => {
s.slide('right');
}, 1000)
Here's a jsfiddle demonstrating that in action: https://jsfiddle.net/shb6tco1/
I suppose you can set the direction in a data-attribute
on the slide as well, although that wouldn't be entirely random as it would be statically set. If you decided to update the data-attribute
of the element on the fly, you would have to keep overwriting the slidr
direction mapping via s.add()
so that the slide can actually travel in the new, random direction.
from slidr.
@BHWD just for fun, here's another fiddle with a totally random direction after each slide: https://jsfiddle.net/zneodqab/
from slidr.
@bchanx this is brilliant! thank you, I can make this work :) 👍
from slidr.
@bchanx is it possible to trigger a nested slidr when the parent slide loads? I have some slides which have another slidr in it too so when the parent loads I'd like to trigger this child slidr. I am able to set any data attribute for reference if required?
from slidr.
Related Issues (20)
- Delay HOT 3
- Next Prev in auto mode
- Creating Sub Categorie Slider
- Slide names in breadcrumbs... HOT 1
- External CSS
- next page/part of content
- Controls not work in opera 20
- Eternal Slider
- Responsive ? HOT 2
- [Slidr] Error adding [horizontal] slides for [testimonials-slider]. HOT 2
- endless loop HOT 2
- href for images HOT 3
- Disable vertical touch only on mobile
- clean/remove all the slidr
- Uncaught TypeError in Chrome
- How to make multiple slides ?! HOT 1
- Centering slide images vertically HOT 2
- Loop
- Add perView property
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from slidr.