JavaScripts -> Textticker -> Marquee-Ersatzscript

Dieses Script mit vielen Optionen kann als Ersatz des Tags <marquee> genutzt werden.

Kompatibilität getestet:
Beispiel Anzeigen >>

Script-Code

<script type="text/javascript">
<!--
// = = ==================================================================== = =
// = = Arsenal Marquee v1.0 (c) 2004 Triple-M / http://www.htmlarsenal.de = =
// = = ==================================================================== = =

// ----------------------------------------------------------------------------
// -- Dieses Script und viele andere im --
// -- This script and many more in the --
// ----------------------------------------------------------------------------
// -- HTML ARSENAL - Die Quelle für HTML, JavaScript, PHP --
// -- HTML ARSENAL - Your Source for HTML, JavaScript, PHP --
// ----------------------------------------------------------------------------
// -- -= http://www.htmlarsenal.de =- --
// ----------------------------------------------------------------------------

// Benutzung
// =========

// Fügen Sie an der Stelle, an der die Laufschrift erscheinen soll, einfach ein Script mit dem Inhalt
// marquee(" text ","option=wert; option=wert; ...");
// ein. Der erste Parameter der Funktion enthält den Text, welcher seinerseits auch HTML-Formatierung
// enthalten kann (Auch Bilder). Mit dem zweiten Parameter können Sie die Darstellung und das Verhalten
// der Laufschrift beeinflussen. Die Syntax ist dabei jeweils
// [optionsname]=[wert];
// wobei das Semikolon zum Abschluss auch noch beim letzten Wert stehen muss.
// Mögliche Optionen:
// speed -> Geschwidigkeit
// direction -> (left/right) Richtung
// halt -> (0/1) Anhalten beim Berühren mit der Maus?
// font -> Schriftart
// color -> Schriftfarbe (in HTML #123456-Syntax)
// background -> Hintergrundfarbe (in HTML #123456-Syntax)
// width -> Wenn der Inhalt breiter als der Ausgabebereich ist, müssen sie die Breite in % des
// Ausgabebereiches hier angeben
//
// BEISPIEL
// marquee("HTML Arsenal - Ihre Quelle f&uuml;r HTML, JavaScript, PHP",
// "color=#c02020; direction=right; font=Verdana; halt=1;");


// Usage
// =====

// Include a script with the content
// marquee(" text ","option=value; option=value; ...");
// at the position where the marquee shall be placed. The first parameter of the function contains
// the text, which is in turn allowed to contain HTML formatting tags (also images). With the second
// parameter you may influence display and behavior of the marquee. The syntax for doing so is always
// [option name]=[value];
// Note: the semicolon finishing the value must even be included for the last value.
// Possible options:
// speed -> speed of the marquee
// direction -> (left/right) scrolling direction
// halt -> (0/1) stop when mouse moves over marquee?
// font -> font
// color -> font color (HTML #123456 syntax)
// background -> background color (HTML #123456 syntax)
// width -> If the content is wider then the display area, you have to specify the content width in
// percent of the dispay area here
//
// EXAMPLE
// marquee("HTML Arsenal - Your source for HTML, JavaScript, PHP",
// "color=#c02020; direction=right; font=Verdana; halt=1;");

// Script-Code
// ===========

// Ab hier bitte nichts mehr verändern
// Please do not change anything from here on

var _speed=50;
var _direction=-1;
var _halt=0;
var _width=100;

var marquee_num=0;

var speed=new Array();
var direction=new Array();
var halt=new Array();
var pos=new Array();
var font=new Array();
var width=new Array();
var running=new Array();

function marquee(text, par) {
  var search, style="";

  speed[marquee_num]=_speed;
  direction[marquee_num]=_direction;
  halt[marquee_num]=_halt;
  pos[marquee_num]=100;
  font[marquee_num]="Arial";
  width[marquee_num]=_width;
  running[marquee_num]=1;

  search=/speed\s*=\s*(.*?);/;
  if(search.test(par)) {
    search.exec(par);
    speed[marquee_num]=RegExp.$1;
  }
  search=/direction\s*=\s*(.*?);/;
  if(search.test(par)) {
    search.exec(par);
    if(RegExp.$1=="left")direction[marquee_num]=-1;
    if(RegExp.$1=="right")direction[marquee_num]=1;
  }
  search=/halt\s*=\s*(.*?);/;
  if(search.test(par)) {
    search.exec(par);
    halt[marquee_num]=RegExp.$1;
  }
  search=/font\s*=\s*(.*?);/;
  if(search.test(par)) {
    search.exec(par);
    font[marquee_num]=RegExp.$1;
  }
  search=/width\s*=\s*(.*?);/;
  if(search.test(par)) {
    search.exec(par);
    width[marquee_num]=RegExp.$1;
  }
  search=/color\s*=\s*(.*?);/;
  if(search.test(par)) {
    search.exec(par);
    style+="color:"+RegExp.$1+"; ";
  }
  search=/background\s*=\s*(.*?);/;
  if(search.test(par)) {
    search.exec(par);
    style+="background-color:"+RegExp.$1+"; ";
  }

  document.write('<div style="margin:0px; padding:0px; width:100%; overflow:hidden">');
  document.write('<div id="marquee_'+marquee_num+'" style="margin:0px; padding:0px; position:relative; left:'+(10000/width[marquee_num])+'%; width:'+width[marquee_num]+'%; overflow:hidden"'+((halt[marquee_num]>0)?(' onMouseOver="running['+marquee_num+']=0" onMouseOut="running['+marquee_num+']=1"'):"")+'>');
  document.write('<pre style="font-family:'+font[marquee_num]+'; margin:0px; padding:0px; '+style+'">'+text+'<\/pre>');
  document.write('<\/div>');
  document.write('<\/div>');
  window.setTimeout("dothemarquee("+marquee_num+")",speed[marquee_num]);
  marquee_num++;
}

function dothemarquee(num) {
  if(running[num]) {
    pos[num]+=(direction[num]*(.5));
    if(pos[num]<-100)pos[num]=Math.round(10000/width[num]);
    if(pos[num]>Math.round(10000/width[num]))pos[num]=-100;
    document.getElementById('marquee_'+num).style.left=pos[num]+"%";
  }
  window.setTimeout("dothemarquee("+num+")",speed[num]);
}

// ----------------------------
// -- Ende / End Script-Code --
// ----------------------------
// -- Arsenal M A R Q U E E --
// -- Author: Triple-M --
// -- www.htmlarsenal.de --
// -- 25.Apr.2004 --
// ----------------------------

//-->
</script>