Monday, August 27, 2012

javascript – jQuery looping a function fails

I have a little problem with jQuery.

I try to show multiple texts in a div. these divs shoud fadein and fadeout and in the end the function should restart.


i wrote a simple example and when it runs. it starts fine…



  1. one

  2. two

  3. three

  4. four

  5. five

  6. six


when the function is looped the problem beginns. it shows the following order:



  1. two

  2. four

  3. five

  4. six

    and starts then over with this order.


i don\’t get it. Can anybody point me in the right direction?


thats the script:



<html>
<head>
<script type=\"text/javascript\" src=\"jquery151.js\"></script>


<script type=\"text/javascript\">
$(document).ready(function() {
function loop() {

var fadeTime = 1000;
var delayTime = 3200;

//if($(\'#layout4TextTitel\').is(\':visible\') ) {
$(\'#layout4TextTitel\').fadeOut(fadeTime, function() {
$(\'#layout4TextTitel\').empty().html(\'one\');
});
$(\'#layout4TextTitel\').fadeIn(1000).delay(delayTime);


$(\'#layout4TextTitel\').fadeOut(fadeTime, function() {
$(\'#layout4TextTitel\').html(\'two\').fadeIn(1000).delay(delayTime);
});

$(\'#layout4TextTitel\').fadeOut(fadeTime, function() {
$(\'#layout4TextTitel\').empty().html(\'three\');
});
$(\'#layout4TextTitel\').fadeIn(fadeTime).delay(delayTime);

$(\'#layout4TextTitel\').fadeOut(fadeTime, function() {
$(\'#layout4TextTitel\').empty().html(\'four\');
});
$(\'#layout4TextTitel\').fadeIn(fadeTime).delay(delayTime);

$(\'#layout4TextTitel\').fadeOut(fadeTime, function() {
$(\'#layout4TextTitel\').empty().html(\'five\');
});
$(\'#layout4TextTitel\').fadeIn(fadeTime).delay(delayTime);

$(\'#layout4TextTitel\').fadeOut(fadeTime, function() {
$(\'#layout4TextTitel\').empty().html(\'six\');
});
$(\'layout4TextTitel\').fadeIn(fadeTime).delay(delayTime);
// Ende for-Schleife

} // Ende loop()

for(var x = 0; x <=1000; x++) {
loop();
} // Ende for-Schleife

});

</script>
</head>
<body>
<div id=\"layout4TextTitel\"></div>
</body>






Rating: 5 out of 5 based on 4 ratings



The post javascript – jQuery looping a function fails appeared first on Javascript ASK.






via Javascript ASK http://javascriptask.phpfogapp.com/javascript-jquery-looping-a-function-fails.html

No comments:

Post a Comment