Maik Wenner: DIV Elemente horizontal Scrollen

Beitrag lesen

Hi.

Zeig  doch mal etwas von Deinem Code bitte!

================

var thumbnode = document.getElementById("scrollcontent");
var scrollsize = thumbnode.style.width;
var scrollspeed = 20;
var spacing = 20;
var thumbs = Array();
var thumbpos = Array();
var scr = null;

function pxtoint(px) {
  return parseInt(px.substring(px,(px.length-2)));
}

function inttopx(px) {
  return String(px+"px");
}

function init() {
  var temp = Array();
  temp = thumbnode.getElementsByTagName("div");
  for (i=0;i<temp.length;i++) {
    thumbs[i] = temp[i];
    thumbpos[i] = 0;
  }
}

function genmovement(x) {
  //Maximal nur 4 Bilder berechnen
  for (i=0;i<=4;i++) {
    thumbpos[i] = inttopx((i*(pxtoint(thumbs[i].style.width)))-x);
  }
  for (i=0;i<=4;i++) {
    thumbs[i].style.left = thumbpos[i];
  }
}

function move(x,sp) {
  if (x > (pxtoint(thumbs[0].style.width)) ) {
    thumbs.push(thumbs[0]);
    thumbs.shift();
    x = 0;
  }
  genmovement(x);
  x++;
  scr=setTimeout("move("+x+","+sp+")",scrollspeed);
}

init();
move(0,scrollspeed);

================

Das ganze steht in einer JavaScript Datei, welche am Ende des HTML Dokumentes eingebunden wird.

Gruß, Maik