Giter Club home page Giter Club logo

Comments (10)

rchrd2 avatar rchrd2 commented on May 23, 2024 2

Here's an improvement on the above code. It resets the autoplay timer when user clicks next.

  (function(){
    var wallopEl = document.querySelector('.Wallop');
    var slider = new Wallop(wallopEl);
    var autoPlayMs = 3000;
    var nextTimeout;
    var loadNext = function() {
      var nextIndex = (slider.currentItemIndex + 1) % slider.allItemsArray.length;
      slider.goTo(nextIndex);
    }
    nextTimeout = setTimeout(function() { loadNext(); }, autoPlayMs);
    slider.on('change', function() {
      clearTimeout(nextTimeout);
      nextTimeout = setTimeout(function() { loadNext(); }, autoPlayMs);
    });
  })();

from wallop.

S1SYPHOS avatar S1SYPHOS commented on May 23, 2024 2

@garethjohnsdesign: Something like this:

(function(){
  var Wallop = require('wallop'),
  wallopEl = document.getElementById('slider'),
  slider = new Wallop(wallopEl, {
    // wallop options, like custom class names, ...
  });
  var autoPlayMs = 4500,
  nextTimeout,
  loadNext = function() {
    var nextIndex = (slider.currentItemIndex + 1) % slider.allItemsArray.length;
    slider.goTo(nextIndex);
  };
  nextTimeout = setTimeout(function() {
    loadNext();
  }, autoPlayMs);
  slider.on('change', function() {
    clearTimeout(nextTimeout);
    nextTimeout = setTimeout(function() {
      loadNext();
    }, autoPlayMs);
  });
  // the code you asked for:
  wallopEl.addEventListener('mouseenter', function() {
    clearTimeout(nextTimeout);
  });
  wallopEl.addEventListener('mouseleave', function() {
    nextTimeout = setTimeout(function() {
      loadNext();
    }, autoPlayMs);
  });
})();

You can see it in action here.

from wallop.

peduarte avatar peduarte commented on May 23, 2024

At the moment, autoplay can be done by youself.
Using the API and Custom Events, you, as the developer, have the flexibility to do pretty much anything.

I really don't know how I feel about adding extra code to the core js file... I want it to be as simple as possible.

I am thinking of creating a series of add-ons, that people can add which inherits the WallopSlider class and extends it to add more featueres if people want, this want, only people who want autoslider get it. Keeping the files small and clean.

Will have a better think about this.

Thanks a lot for raising this issue.

from wallop.

sprankhub avatar sprankhub commented on May 23, 2024

Having an add-on for that sounds great. Would love to have that :-)

from wallop.

JorisLambrechts avatar JorisLambrechts commented on May 23, 2024

I used the following to get it to autoplay

jQuery(document).ready(function() {
         var photoslider = new WallopSlider('.photo-slider');
//autoplay
    var count = photoslider.allItemsArrayLength;
    var start = photoslider.currentItemIndex;
    var end = count+1;
    var index = start;    

    jQuery(function(){
        setInterval(function() {
            photoslider.goTo(index);     
            ++index;
            if (index == end) {index=start}
        },3000);
    });

from wallop.

peduarte avatar peduarte commented on May 23, 2024

Yep. Something like that sounds about right. :)

from wallop.

S1SYPHOS avatar S1SYPHOS commented on May 23, 2024

Working great, thx for the code @rchrd2, but is there an easy way to implement pause-on-hover functionality?

from wallop.

honzabilek4 avatar honzabilek4 commented on May 23, 2024

Simply add a new listener on mouseenter with clearTimeout(nextTimeout) and set it back on mouseleave :)

from wallop.

S1SYPHOS avatar S1SYPHOS commented on May 23, 2024

from wallop.

garethjohnsdesign avatar garethjohnsdesign commented on May 23, 2024

Can you give an example of this code? @honzabilek4

from wallop.

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.