Bonjour,
voici un code trouvé ici :
<div id="typewriterBox"></div>
Avec jQuery :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script type="text/javascript">
var text = 'Hello World, Boy ! <br /><a href="#mon_lien">Life is Big</a> !'
var currentChar = 1;
var htmltag = false;
var cache = '';
function typewriter()
{
var str = text.substr(0, currentChar);
var last = str.substr(str.length -1, str.length);
if(last != '<' && last != '>' & last != '/') {
$("#typewriterBox").html(str);
}
currentChar++;
if(currentChar <= text.length)
{
if(last == '<') {
htmltag = true;
} else if(last == '>') {
htmltag = false;
}
if(htmltag) {
setTimeout(typewriter, 1);
} else {
setTimeout(typewriter, 75);
}
}
}
$(document).ready(function() {
$("#typewriterBox").html('');
setTimeout(typewriter, 2000); // début d'affichage après 2s
});
</script> |
Sans :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| <script type="text/javascript">
var text = 'Hello World, Boy ! <br /><a href="#mon_lien">Life is Big</a> !'
var currentChar = 1;
var htmltag = false;
var cache = '';
function typewriter()
{
var str = text.substr(0, currentChar);
var last = str.substr(str.length -1, str.length);
if(last != '<' && last != '>' & last != '/') {
document.getElementById('typewriterBox').innerHTML = str;
}
currentChar++;
if(currentChar <= text.length)
{
if(last == '<') {
htmltag = true;
} else if(last == '>') {
htmltag = false;
}
if(htmltag) {
setTimeout(typewriter, 1);
} else {
setTimeout(typewriter, 75);
}
}
}
function loadtypewriter(){
document.getElementById('typewriterBox').innerHTML = '';
setTimeout(typewriter, 2000); // début d'affichage après 2s
}
window.onload = loadtypewriter;
</script> |
Partager