JavaScript Ticker

Beispiel: ohne großes Framework
Code:
ticker.htm HTML (2,43 kByte) 31.05.2020 00:10
<!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 link = ticker.firstElementChild;
    if (link) {
      var width = (link.style.width ? parseFloat(link.style.width, 10) : link.offsetWidth) + 75;
      ticker.insertBefore(link.cloneNode(true), link);
      ticker.insertBefore(link.cloneNode(true), link);
      var value = 0;
      var tick = function() {
        value--;
        if (value < -width) {
          value = 0;
          ticker.appendChild(ticker.childNodes[0]);
        };
        ticker.childNodes[0].style.setProperty('left', value+'px');
        ticker.childNodes[1].style.setProperty('left', width+value+'px');
        ticker.childNodes[2].style.setProperty('left', 2*width+value+'px');
        window.requestAnimationFrame(tick);
      };
      window.requestAnimationFrame(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>
      .ticker{border:1px solid black; width:400px; height:18px; overflow:hidden; position:relative; white-space:nowrap;}
      .ticker a{display:inline-block; position:absolute; top:0; 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>

Author: , published: , last modified:

Kontakt

Udo Schmal

Udo Schmal
Softwareentwickler
Olvengraben 41
47608 Geldern
Nordrhein-Westfalen
Germany





+49 2831 9776557
+49 1575 0663676
+49 2831 1328709
SMS
WhatsApp

Instagram Profile
vCard 3.0

Copyright / License of sources

Copyright (c) 2007-2020, 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.78
Description:
All in one Webserver
Copyright:
Udo Schmal
Compilation:
Sun, 8. Nov 2020 17:33:03
Development Info Compiler:
Free Pascal FPC 3.3.1
compiled for:
OS:Linux, CPU:x86_64
System Info OS:
Ubuntu 20.04.1 LTS focal
Hardware Info Model:
Hewlett-Packard HP Pavilion dv7 Notebook PC
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), 1157.089 MHz