2

I have that code in jQuery:

function lshow() {
        var delayt = 500;
        var showtime = 5000;
        var ArrayOfElements = ['.slogan1','.whatwedo','.ekon','.ene', '.ekol', '.sm'];
        var i=0;

        $.each(ArrayOfElements,function (i,element) {
            if($(element).is(':visible')) {
                $(element).delay(delayt).hide('slow');
            }
            if ($(element).is(':hidden')) {
                $(element).delay(showtime).show('slow');
            }

        });
    }

and HTML:

<span class="slogan">
    <span class="slogan1">my slogan</span><!--Default visible-->
        <span class="whatwedo"><!--Default invisible-->
            projects <span class="sm">and modernization </span> of something <span class="ekon">fine</span>
        <span class="ene">fast</span>
        <span class="ekol">smooth</span>
    </span>
</span>

CSS:

.whatwedo, .sm, .ene, .ekol {
   display: none;
}

And I want to set it appear like that:

  1. My slogan

fadeOut

  1. projects of something fine

"fine" fadeOut "fast" fadeIn

  1. projects of something fast

same thing

  1. projects of something smoth
  2. projects and modernization of something

But after 5 sec. it shows "projects and modernization of something fine fast smoth" and i cant get it working

4 Answers 4

5

Try this http://jsfiddle.net/Kt38f/

 $(document).ready(function() {
    var delayt = 500;
    var showtime = 5000;
    var ArrayOfElements = ['.slogan1','.whatwedo','.ekon','.ene', '.ekol', '.sm'];
    var i=0;

            $('.slogan1').fadeOut(delayt, function(){        
                $(".whatwedo").fadeIn(showtime , function(){
                    $('.ekon').fadeOut(showtime , function(){ 
                        $('.ene').fadeIn(showtime, function(){
                            $('.ene').fadeOut(showtime, function(){ 
                                $('.ekol').fadeIn(showtime, function(){ 
                                   $('.sm').fadeIn(showtime);
                                });
                            });   
                        });
                    });
                });
            });         
});
Sign up to request clarification or add additional context in comments.

2 Comments

you could do it with $.when() and .then(), but you still end up with a lot of chained stuff...
Hmm not exactly. Span appear before the previous is hided so ther's a white space.
1

Here is another way:

Instead of putting the elements in an array, you put the functions that should be executed in an array and process it using setTimeout:

function lshow() {
    var intv = 5000;
    var funcs = [
        function() {
            $('.slogan1').hide('slow');
            $('.whatwedo').show('slow');
        },
        function() {
            $('.ekon').hide('slow');
            $('.ene').show('slow');
        },
        function() {
            $('.ene').hide('slow');
            $('.ekol').show('slow');
        },
        function() {
            $('.sm').show('slow');
        }
    ];
    var i = 0;

    setTimeout(function() {
        var func = funcs[i];
        if(func) {
            i++;
            func();
            setTimeout(arguments.callee, intv);
        }
    }, intv);
}

DEMO

Comments

1

I took a little bit of a different approach to it. Fiddle @ http://jsfiddle.net/SinS3i/xwc9a/1/

var currentStep = false;
var t = false;
ArrayOfElements = ['.slogan1','.whatwedo','.ekon','.ene', '.ekol', '.sm'];
var delayt = 500;
var showtime = 5000;
lshow = function(elements) {
    var lastStep = currentStep;
    currentStep = elements.shift();
    var hideIt = lastStep ? $(lastStep).has(currentStep).length === 0 : false;
    if(hideIt) {
        $(lastStep).fadeOut(showtime, function() {
            $(currentStep).fadeIn(showtime, function() {
                t = ArrayOfElements.length > 0 ? setTimeout("lshow(ArrayOfElements)", delayt) : false;                    
            });
        });
    } else {
        $(currentStep).fadeIn(showtime, function() {
            t = ArrayOfElements.length > 0 ? setTimeout("lshow(ArrayOfElements)", delayt) : false;
        });
    }
};
$(document).ready(function(){
    t = setTimeout("lshow(ArrayOfElements)", delayt);
});

Comments

0

Little bit edited (http://jsfiddle.net/dVJvc/):

EDIT: Sorry i didnt see yours responses. (THE CODE IS THAT SAME AS last ShankarSangoli)

1 Comment

Is this an answer or an addition to your question? If the latter, please edit your question instead.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.