Solved

jQuery Pause on Hover

Posted on 2014-07-25
11
439 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
Comment Utility
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
Comment Utility
Hello leakim, that was not loading.
0
 
LVL 58

Assisted Solution

by:Gary
Gary earned 50 total points
Comment Utility
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
Comment Utility
Leakim is totally grooooovy, but the jsfiddle is not working when I go to it
0
 
LVL 82

Expert Comment

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

var go_away = false;

Open in new window

0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 1

Author Closing Comment

by:movieprodw
Comment Utility
So awesome! Thanks guys!
0
 
LVL 1

Author Comment

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

Expert Comment

by:leakim971
Comment Utility
what this line supposed to do ?

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

Author Comment

by:movieprodw
Comment Utility
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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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)

763 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

6 Experts available now in Live!

Get 1:1 Help Now