Comments (10)
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.
@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.
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.
Having an add-on for that sounds great. Would love to have that :-)
from wallop.
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.
Yep. Something like that sounds about right. :)
from wallop.
Working great, thx for the code @rchrd2, but is there an easy way to implement pause-on-hover functionality?
from wallop.
Simply add a new listener on mouseenter
with clearTimeout(nextTimeout)
and set it back on mouseleave
:)
from wallop.
from wallop.
Can you give an example of this code? @honzabilek4
from wallop.
Related Issues (20)
- Collaboration HOT 1
- Autostart reset timer HOT 1
- Expose method for updating global variables HOT 4
- How to import it in an angular 2 project? HOT 3
- How about multiple columns? HOT 5
- New modifiers: show & hide HOT 2
- New example: Wallop with Custom Markup HOT 1
- Uncaught (in promise) Error HOT 14
- Wallop is not a constructor HOT 1
- Include main in bower.json too HOT 2
- Wrong behaviour for slider with two slides
- slider autoplay HOT 1
- Which browsers are supported? HOT 1
- Can't resolve 'Wallopโ when building on linux HOT 4
- Problem with absolute positioned items, flexbox and Firefox HOT 3
- equal height slides HOT 4
- All images broken on CodePen examples collection
- .mp4 videos in slide don't work in Chrome HOT 1
- Slide effect in Safari not nice
- Consuta Blancos entre distintas imagenes;
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 wallop.