Coder Social home page Coder Social logo

Comments (4)

bchanx avatar bchanx commented on May 29, 2024 1

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.

bchanx avatar bchanx commented on May 29, 2024 1

@BHWD just for fun, here's another fiddle with a totally random direction after each slide: https://jsfiddle.net/zneodqab/

from slidr.

BHWD avatar BHWD commented on May 29, 2024

@bchanx this is brilliant! thank you, I can make this work :) 👍

from slidr.

BHWD avatar BHWD commented on May 29, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.