Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop autoplay while hovering #191

Closed
stereodenis opened this issue May 30, 2013 · 14 comments
Closed

Stop autoplay while hovering #191

stereodenis opened this issue May 30, 2013 · 14 comments

Comments

@stereodenis
Copy link

There is no option for that

@nolimits4web
Copy link
Owner

Right, and will not be. You can call .stopAutoPlay() and .startAutoPlay() within jQuery's .hover handlers http:https://api.jquery.com/hover/

@ptz-nerf
Copy link

Seems .stopAutoplay() and .startAutoplay don't work on the latest version. Tested on default demo by adding $('.swiper-container').hover(mySwiper.stopAutoplay(),mySwiper.startAutoplay()).

@mairead
Copy link

mairead commented Jul 11, 2013

stopAutoplay not working for me either.

@nolimits4web
Copy link
Owner

@mairead give me a link to your project so i can take a look

@mehernosh
Copy link
Contributor

Hey @nolimits4web
Awesome work! Saved me a load of time, Thanks!

@ptz-nerf, @mairead
use https://github.com/mehernosh/Swiper/blob/master/dev/idangerous.swiper.js if you are in a hurry.

nolimits4web added a commit that referenced this issue Jul 14, 2013
Fixes autoplay bug mentioned in #191 comments
@ghost
Copy link

ghost commented Mar 15, 2017

$(".swiper-container").hover(function(){
swiper.stopAutoplay();
}, function(){
swiper.startAutoplay();
});

@monty-georgiev
Copy link

What if you have more than one instance? How would you reuse the stop and play functions?
Can you get the instance and do something like:

$(".swiper-container").hover(function(){
[getTheInstance].stopAutoplay();
}, function(){
[getTheInstance].startAutoplay();
});

@ptz-nerf
Copy link

ptz-nerf commented Apr 7, 2017

var mySwiper = $('.swiper-container')[0].swiper;`

But during initialization your already have instance:

var mySwiper = new Swiper('#target');
$("#target").hover(function(){
     mySwiper.stopAutoplay();
}, function(){
     mySwiper.startAutoplay();
});

@monty-georgiev
Copy link

monty-georgiev commented Apr 8, 2017

Your approach suggests that if I have 3 instances (e.g. swiper1, swiper2, swiper3) and I want to stop the autoplay on hover, then I should go and do this block for each one of them like so:

$('#target1).hover(function(){swiper1.stopAutoplay}, function(){swiper1.startAutoplay});
$('#target2).hover(function(){swiper2.stopAutoplay}, function(){swiper2.startAutoplay});
$('#target3).hover(function(){swiper3.stopAutoplay}, function(){swiper3.startAutoplay});

However that's not really DRY is it?

Instead, the following solution, that I found, works way better:

$(".swiper-container").hover(function(){
     this.swiper.stopAutoplay();
}, function(){
     this.swiper.startAutoplay();
});

So this is how you get the instance without referencing to the variables

@ptz-nerf
Copy link

ptz-nerf commented Apr 8, 2017

  1. If you have 3 instances with same configuration, it is better to write some function which creates them.
  2. I'm glad that you have found a solution. Note this.swiper and $('.swiper-container')[0].swiper are the same. My code is just copy-paste from API docs.

@qJake
Copy link

qJake commented May 16, 2017

The code @monty-georgiev posted should be included as an option in swiper. I shouldn't have to hack the library with jQuery in order to get some desired functionality. :)

@davidwwu
Copy link

davidwwu commented Nov 2, 2017

I'm getting start/stopAutoplay() is not a function error. Any idea?

@davidwwu
Copy link

davidwwu commented Nov 2, 2017

NVM, just found the solution in the api documentation:

$(".swiper-container").hover(function() {
    swiper.autoplay.stop();
}, function() {
    swiper.autoplay.start();
});

@killmanda
Copy link

no jQuery solution

var mySwiper = new Swiper ('#target')
mySwiper.el.addEventListener("mouseenter", function( event ) {   
	mySwiper.autoplay.stop();
}, false);

@lock lock bot added the outdated label Dec 30, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Dec 30, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants