JavaScript Ticker

Beispiel: ohne großes Framework
Code:
ticker.htm HTML (2,43 kByte) 01.09.2015 21: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-2017, 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
UDOs Webserver

0.3.1.24

All in one Webserver

Udo Schmal

Sa, 21 Okt 2017 00:30:10
Development Info
Lazarus LCL 1.9.0.0

Free Pascal FPC 3.1.1

OS:Win64, CPU:x86_64
Hardware Info
Precision WorkStation T3500

Intel(R) Xeon(R) CPU W3530 @ 2.80GHz

x86_64, 1 physical CPU(s), 4 Core(s), 8 logical CPU(s), 2800 MHz