JavaScript Ticker

Beispiel: ohne großes Framework
Code:
ticker.htm HTML (2,43 kByte) 01.09.2015 22:59
<!DOCTYPE html >
<html lang="en">
  <head><meta charset="utf-8" />
    <title>Ticker</title>
    <script type="text/javascript">
      /* <![CDATA[ */
window.requestAnimFrame = (function(){
  return  window.requestAnimationFrame       ||
          window.webkitRequestAnimationFrame ||
          window.mozRequestAnimationFrame    ||
          function(callback){
            window.setTimeout(callback, 1000 / 60);
          };
})();

function getElementsByClassName(searchClass, tagName, domNode) {
  if (domNode == null) domNode = document;
  if (tagName == null) tagName = '*';
  var el = new Array();
  var tags = domNode.getElementsByTagName(tagName);
  var tcl = " "+searchClass+" ";
  for(var i=0,j=0; i<tags.length; i++) {
    var test = " " + tags[i].className + " ";
    if (test.indexOf(tcl) != -1) {
      el[j++] = tags[i];
    }
  };
  return el;
}

function jsTicker() {
}
jsTicker.prototype = {
  init: function(ticker) {
    var width = (ticker.style.width ? parseFloat(ticker.style.width, 10) : ticker.offsetWidth) + 15;
    var wrapper = document.createElement('div');
    wrapper.className = 'tickerWrapper';
    ticker.parentNode.insertBefore(wrapper, ticker);
    wrapper.appendChild(ticker);
    var clone = ticker.cloneNode(true);
    wrapper.appendChild(clone);
    var value = 0;
    var tick = function() {
      value--;
      if (value < -width) {
        value = 0;
        wrapper.appendChild(wrapper.childNodes[0]);
      };
      wrapper.childNodes[0].style.setProperty('left', value+'px');
      wrapper.childNodes[1].style.setProperty('left', width+value+'px');
      window.requestAnimFrame(tick);
    };
    window.requestAnimFrame(tick);
  }
}

function init() {
  var tickerList = getElementsByClassName("ticker", "div");
  for (var i=0; i<tickerList.length; i++) {
    var ticker = new jsTicker();
    ticker.init(tickerList[i]);     
  };
}
function ready(f){/complete|loaded/i.test(document.readyState)?f():setTimeout("ready("+f+")",9)}
ready(init);
/* ]]> */
    </script>
    <style>
      .tickerWrapper{border:1px solid black; width:400px; height:18px; overflow:hidden; position:relative; white-space:nowrap;}
      .ticker{display:inline-block; position:absolute; top:0;}
      .ticker a{text-decoration:none;}
    </style>
  </head>
  <body>
    <div class="ticker"><a href="/Scheffau-2014">Bilder vom Urlaub in Scheffau am Wilden Kaiser 2014</a></div>
  </body>
</html>

Autor: , veröffentlicht: , letzte Änderung:

Kontakt

Copyright / License of sources

Copyright (c) 2007-2018, Udo Schmal <udo.schmal@t-online.de>

Permission to use, copy, modify, and/or distribute the software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

Service Infos

CMS Info Product Name:
UDOs Webserver
Version:
0.4.2.18
Description:
All in one Webserver
Copyright:
Udo Schmal
Compilation:
Mo, 26 Nov 2018 00:11:09
Development Info Compiler:
Free Pascal FPC 3.3.1
compiled for:
OS:Linux, CPU:x86_64
Hardware Info Model:
Hewlett-Packard 1800
CPU Name:
Intel(R) Core(TM) i5-2450M CPU @ 2.50GHz
CPU Type:
x86_64, 1 physical CPU(s), 2 Core(s), 4 logical CPU(s), 1085.151 MHz
System Info OS:
Ubuntu 18.04.1 LTS bionic