1
<div id="par">
  <div id="item11"></div>
  <div id="item12"></div>
  <div id="item13"></div>
  <div id="item14"></div>
  ....
</div>

div#itemXX要素を内部で自動スクロールアップさせたいdiv#par。また、毎回1div移動させたいです。

タグは使用できますが、<marquee>廃止されましたので、他に方法はありませんか?

ところで、の高さはdiv#itemXX固定されていません。

更新: 「div#itemXX」を毎回1つずつ移動したい。スライドショーと同じように、毎回1つのdivを表示しますが、現在のdivの高さがビューポートよりも大きい場合は上にスクロールし、スクロールが終了すると次のdiv(スライド)が上に移動します。

4

1 に答える 1

3
(function(){
var top=0;
var par = document.getElementById('par')
var scroll = function() {
  top++;
  if( top>=par.firstElementChild.offsetHeight )
  {
    //first element is out of sight, so move to the end of the list
    top=0;
    par.firstElementChild.style.marginTop='';//reset to zero
    par.appendChild(par.firstElementChild);
  }
  else
  {
     //move the first element 'top' px up
     par.firstElementChild.style.marginTop='-'+top+'px';
  }
  setTimeout(scroll, 100);//repeat after 100ms
}
scroll();
})()

jsbin: http: //jsbin.com/onohan/3/

于 2011-07-09T11:06:33.440 に答える