stop animations in functions
Hi
I have images that fade in an out in the background. I've put them in functions.
When clicking on a button I want them all to fade and stop running.
I find no way of doing this.
I have tried using stop(), clearQueue() and finish() in different ways but nothing works?
This is my code:
- function aniBG2() {
- bg2.delay(4000).animate({ opacity: 1,
- }, 10000, function() {
-
- bg3.animate({ opacity: 1,
- }, 10000, function() {
-
- bg3.delay(5000).animate({ opacity: 0,
- }, 10000, function() {
-
- bg2.animate({ opacity: 0,
- }, 10000, function() {
- aniBG2();
- });
- });
- });
- });
- }
- function aniBG4() {
- bg4.delay(7000).animate({ opacity: 1,
- }, 10000, function() {
-
- bg4.delay(4000).animate({ opacity: 0,
- }, 10000, function() {
- aniBG4();
- });
- });
- }
- function aniBG5() {
- bg5.delay(2000).animate({
- opacity: 1,
- }, 10000, function() {
-
- bg5.delay(6000).animate({
- opacity: 0,
- }, 10000, function() {
- aniBG5();
- });
- });
- }
-
-
-
- $('#logo').on('click', function(e){
- bg2.stop(true,true).animate({opacity: 0}, function() {
- bg2.clearQueue().finish();
- });
- bg3.stop(true,true).animate({opacity: 0}, function() {
- bg3.clearQueue().finish();
- });
- bg4.stop(true,true).animate({opacity: 0}, function() {
- bg4.clearQueue().finish();
- });
- bg5.stop(true,true).animate({opacity: 0}, function() {
- bg5.clearQueue().finish();
- });
- });
Grateful for help.