Solved

jQuery Pause on Hover

Posted on 2014-07-25
11
446 Views
Last Modified: 2014-07-28
Hello,

Can you please help me find a way to pause the slideshow if the mouse is over it?

http://jsfiddle.net/g7aBe/2/

Matt
0
Comment
Question by:movieprodw
  • 6
  • 4
11 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 450 total points
ID: 40220726
http://jsfiddle.net/g7aBe/5/

jQuery(function($) {
     var divs = $('.fade');
	 
	 function fade() {
         if(go_away) return;
		var current = $('.current');
		var currentIndex = divs.index(current),
			nextIndex = currentIndex + 1;
		
		if (nextIndex >= divs.length) {
			nextIndex = 0;
		}
		
		var next = divs.eq(nextIndex);
		
		current.stop().fadeOut(1000, function() {
			$(this).removeClass('current');
			setTimeout(fade, 6000);
		});

		next.stop().fadeIn(1000, function() {
			$(this).addClass('current');
		});
		
	}

     fade();
    
    var stop = function() {
        go_away = true;
    }
    var release = function() {
        go_away = false;
    }
    
    $("#wrapper").hover(stop, release);
})

Open in new window

0
 
LVL 1

Author Comment

by:movieprodw
ID: 40220729
Hello leakim, that was not loading.
0
 
LVL 58

Assisted Solution

by:Gary
Gary earned 50 total points
ID: 40220730
Leakim's solution is kinda groovy so give him the point, here's another method
Name your timeout then you can cancel/restart it.

donext = setTimeout(fade, 6000);

    $("#wrapper").hover(function(){
      clearTimeout(donext)  
    },function(){
      donext = setTimeout(fade, 6000);  
    })


http://jsfiddle.net/GaryC123/g7aBe/7/
0
 
LVL 1

Author Comment

by:movieprodw
ID: 40220733
Leakim is totally grooooovy, but the jsfiddle is not working when I go to it
0
 
LVL 82

Expert Comment

by:leakim971
ID: 40220742
@Gary is right, I forgot to set the default value : http://jsfiddle.net/g7aBe/11/

var go_away = false;

Open in new window

0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 1

Author Closing Comment

by:movieprodw
ID: 40220751
So awesome! Thanks guys!
0
 
LVL 1

Author Comment

by:movieprodw
ID: 40222049
Any idea why it is not working here?
http://dev.zdental.com/
0
 
LVL 82

Expert Comment

by:leakim971
ID: 40222478
what this line supposed to do ?

$("#wrapper").hover(function() {
0
 
LVL 1

Author Comment

by:movieprodw
ID: 40223321
So you're saying I am a goof :=P

I will change that to .banner-box, and test again, thanks!
0
 
LVL 1

Author Comment

by:movieprodw
ID: 40223322
It doesn't really matter for my purposes but for me if I have the mouse over this for lets say 10 seconds then move it, the slideshow never starts again.

http://jsfiddle.net/g7aBe/11/

Not complaining, you helped me a lot, thank you.
0
 
LVL 82

Expert Comment

by:leakim971
ID: 40224440
So you're saying I am a goof :=P

lol, no, just want to be sure your own the code, look like yes ;-))

http://jsfiddle.net/g7aBe/12/
call fade when release
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now