fadein - JQuery text fade in fade out -
i
- replace word "." "first"
- after 1 sec, replace word "first" "second"
- after 1 sec, replace word "second" "first"
- after 1 sec, replace word "first" "second"
- after 1 sec, replace word "second" "first"
- repeatedly continue cycle
however code not work expected. - instead appends word previous word.
could please suggest how approach problem? thank you. http://codepen.io/anon/pen/oywpqq
<h2 class="quotes"><span class="typebg"><span class="type">.</span></span> <span class="details"><a href="#"><span class="detailstext">.</span></a></span> <span class="cta"><a href="#"><span class="ctatext">.</span></a></span></h2> .quotes {height:45px !important;margin-top:-17.5px;margin-bottom:17.5px;border:1px solid #bec0c2;padding:10px 0px;} .typebg{height:44px;top:-10px;position:relative;padding:10px 15px;background-color:#004a65;color:white;width:140px;white-space: nowrap; text-overflow: ellipsis; overflow:hidden;display:inline-block;} .type{display:none;} .cta,.details{border:1px solid #bec0c2;padding:10px 2px;top:-11px;position:relative;background-color:white;} .cta{height:41px !important;width:138px;text-align:right;white-space: nowrap; text-overflow: ellipsis; overflow:hidden;display:inline-block;} .details{height:40px !important; white-space: nowrap; text-overflow: ellipsis; overflow:hidden;width:736px;display:inline-block;} showfirst(); function showfirst() { $('<span/>').html("first").appendto($(".detailstext")); $(".detailstext").fadein(500).delay(1000).fadeout(500,showsecond); } function showsecond() { $('<span/>').html("second ").appendto($(".detailstext")); $(".detailstext").fadein(500).delay(3000).fadeout(500); showfirst(); }
you appending text rather replacing it. figure out minimal solution below
$(document).ready(function() { var countertext = ["first", "second", "third"]; var counter = 0; setinterval(change, 1000); function change() { $('.detailstext').html(countertext[counter]); counter++; if(counter >= countertext.length) { counter = 0; } } })
.quotes {height:45px !important;margin-top:-17.5px;margin-bottom:17.5px;border:1px solid #bec0c2;padding:10px 0px;} .typebg{height:44px;top:-10px;position:relative;padding:10px 15px;background-color:#004a65;color:white;width:140px;white-space: nowrap; text-overflow: ellipsis; overflow:hidden;display:inline-block;} .type{display:none;} .cta,.details{border:1px solid #bec0c2;padding:10px 2px;top:-11px;position:relative;background-color:white;} .cta{height:41px !important;width:138px;text-align:right;white-space: nowrap; text-overflow: ellipsis; overflow:hidden;display:inline-block;} .details{height:40px !important; white-space: nowrap; text-overflow: ellipsis; overflow:hidden;width:736px;display:inline-block;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> <h2 class="quotes"><span class="typebg"><span class="type">.</span></span> <span class="details"><a href="#"><span class="detailstext">.</span></a></span> <span class="cta"><a href="#"><span class="ctatext">.</span></a></span></h2>
checkout http://codepen.io/anon/pen/zvnzmz
Comments
Post a Comment