|
Exemples de JavaScript
4. Défilement de texte
4.1 Dans un document
Il faut inclure ce Script dans l'en-tête :
<SCRIPT LANGUAGE="JavaScript">
var id,pause=0,position=0;
function banner() {
var i,k,speed=10,msg="Mettre ici le texte";
k=(66/msg.length)+1;
for(i=0;i<=k;i++) msg+=" "+msg;
document.defil.banner.value=msg.substring(position,position+50);
if(position++==msg.length) position=0;
id=setTimeout("banner()",1000/speed); }
</SCRIPT>
Ainsi qu'inclure dans <BODY> : <BODY ... OnLoad="banner()">
Et le formulaire dans le document :
<FORM NAME="defil">
<INPUT TYPE="text" NAME="banner" SIZE="40">
</FORM>
4.2 Dans la barre d'état
Il faut inclure ce Script dans l'en-tête :
<SCRIPT LANGUAGE="JavaScript">
var id,pause=0,position=0;
function banner() {
var i,k,speed=10,msg="Mettre ici le texte";
k=(66/msg.length)+1;
for(i=0;i<=k;i++) msg+=" "+msg;
window.status=msg.substring(position,position+100);
if(position++==msg.length) position=0;
id=setTimeout("banner()",1000/speed); }
</SCRIPT>
Ainsi qu'inclure dans<BODY> : <BODY ... OnLoad="banner()">
4.3 Ping Pong
Attention :
Cette routine a un Copyright (©) vous devez laisser les commentaires si vous l'utilisez, mais vous pouvez changer le texte qui défile...
Il faut inclure ce Script dans l'en-tête :
<SCRIPT LANGUAGE="JavaScript">
<!--
/* MjM'S JAVA CODENAME = PINGPONG
This JavaScript Code was written by MjM for Hyperchat UK
I am not responsible for any damage caused by my code.
This code can be modified as long as the Author's Name is still attached.
Email : MjM@hyperchat.co.uk
© Copyright 1996
*/
var yourwords = "* MjM's HTML & JavaScript Guide - http://hyperchat.co.uk/u/mjm/guide.htm *";
var buffer1=" ";
var buffer2=" ";
var message1=buffer1+yourwords+buffer2;
var dir = "left";
var speed = 75;
function pingpong()
{
if (dir == "left")
{
message2=message1.substring(2,message1.length)+" ";
window.status=message2;
setTimeout("pingpong();",speed);
message1=message2;
if (message1.substring(0,1) == "*") dir="right";
}
else
{
message2=" "+message1.substring(0,message1.length-2);
window.status=message2;
setTimeout("pingpong();",speed);
message1=message2;
if (message1.substring(message1.length-1,message1.length) == "*") dir="left";
}
}
// -->
</SCRIPT>
Ainsi qu'inclure dans<BODY> : <BODY ... OnLoad="pingpong()">
4.4 Scrolling
Attention :
Cette routine a un Copyright (©) vous devez laisser les commentaires si vous l'utilisez, mais vous pouvez changer le texte qui défile...
Il faut inclure ce Script dans l'en-tête :
<SCRIPT LANGUAGE="JavaScript">
<!--
/*
Copyright (C) 1996 Frequency Graphics All Rights Reserved.
Feel free to reuse or modify this code,
provided this header remains in tact
Andy Augustine 2.26.96 [www.FreqGrafx.com]
*/
function snapIn(jumpSpaces,position) {
var msg = "Bienvenue!! . . . Welcome to the Gustave Eiffel's Pages ! ! . . ."
var out = ""
if (killScroll) {return false}
for (var i=0; i<position; i++)
{out += msg.charAt(i)}
for (i=1;i<jumpSpaces;i++)
{out += " "}
out += msg.charAt(position)
window.status = out
if (jumpSpaces <= 1) {
position++
if (msg.charAt(position) == ' ')
{position++ }
jumpSpaces = 100-position
} else if (jumpSpaces > 3)
{jumpSpaces *= .75}
else
{jumpSpaces--}
if (position != msg.length) {
var cmd = "snapIn(" + jumpSpaces + "," + position + ")";
scrollID = window.setTimeout(cmd,5);
} else {
scrolling = false
return false
}
return true
}
function snapSetup() {
if (scrolling)
if (!confirm('Re-initialize snapIn?'))
return false // only way to break the function
// if its already running
killScroll = true // will cause recursive snapIn to break
scrolling = true // sets so that this function can't run twice
// without breaking the first instance
var killID = window.setTimeout('killScroll=false',6)
// now that first occurance was killed,
// reset it so that this instance can proceed
scrollID = window.setTimeout('snapIn(100,0)',10)
// make sure it waits until killScroll is reset
return true //must return true to comply with above break
}
//-------------------------------------------------------------
var scrollID = Object
var scrolling = false
var killScroll = false
//-------------------------------------------------------------
// -->
</SCRIPT>
Ainsi qu'inclure dans<BODY> : <BODY ... OnLoad="snapSetup()">
|
|