Solved

jQuery Pause on Hover

Posted on 2014-07-25
11
455 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 
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
 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Google Tag Manager - Add Trigger Using Div class 22 55
Validating Date Part2 2 27
Can't get js code to execute 8 30
TypeError jquery issues with site - CSS conflicts 3 25
Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

762 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