본문 바로가기
하기

자바스크립트 롤링

by khany 2008. 10. 14.

<script language="javascript">
<!--
// 스트롤 (최근 등록된 10개의 메시지가 롤링됨)

function scroll() {
 this.name = "scroll";
 this.item = new Array();
 this.itemcount = 0;
 this.currentspeed = 0;
 this.scrollspeed = 50;
 this.pausedelay = 1000;
 this.pausemouseover = false;
 this.stop = false;
 this.type = 1;
 this.height = 100;
 this.width = 100;
 this.stopHeight=0;
 this.add =function () {
  var text = arguments[0];
  this.item[this.itemcount] = text;
  this.itemcount = this.itemcount + 1;
 };
 this.start = function () {
  this.display();
  this.currentspeed = this.scrollspeed;
  setTimeout(this.name+'.scroll()',this.currentspeed);
 };
 this.display =function () {
  document.write('<div id="'+this.name+'" style="height:'+this.height+';width:'+this.width+';position:relative;overflow:hidden;" OnMouseOver="'+this.name+'.onmouseover();" OnMouseOut="'+this.name+'.onmouseout();">');
  for(var i = 0; i < this.itemcount; i++) {
   if ( this.type == 1) {
    document.write('<div id="'+this.name+'item'+i+'"style="left:0px;width:'+this.width+';position:absolute;top:'+(this.height*i+1)+'px;">');
    document.write(this.item[i]);
    document.write('</div>');
   }
   else if ( this.type == 2 ) {
    document.write('<div id="'+this.name+'item'+i+'"style="left:'+(this.width*i+1)+'px;width:'+this.width+';position:absolute;top:0px;">');
    document.write(this.item[i]);
    document.write('</div>');
   }
  }
  document.write('</div>');
 };
 this.scroll = function () {
  this.currentspeed = this.scrollspeed;
  if ( !this.stop ) {
   for (i = 0; i < this.itemcount; i++) {
    obj = document.getElementById(this.name+'item'+i).style;
    if ( this.type == 1 ) {
     obj.top = parseInt(obj.top) - 1;
     if ( parseInt(obj.top) <= this.height*(-1) ) obj.top = this.height * (this.itemcount-1);
     if ( parseInt(obj.top) == 0 || ( this.stopHeight > 0 && this.stopHeight - parseInt(obj.top) == 0 ) ) this.currentspeed = this.pausedelay;
    }
    else if ( this.type == 2 ) {
     obj.left = parseInt(obj.left) - 1;
     if ( parseInt(obj.left) <= this.left*(-1) ) obj.left = this.left* (this.itemcount-1);
     if ( parseInt(obj.left) == 0 ) this.currentspeed = this.pausedelay;
    }
   }
  }
  window.setTimeout(this.name+".scroll()",this.currentspeed);
 };
 this.onmouseover = function () {
  if ( this.pausemouseover ) {
   this.stop = true;
  }
 };
 this.onmouseout = function () {
  if ( this.pausemouseover ) {
   this.stop = false;
  }
 };
}
</script>
 
   <div style="text-align:left;margin:25px 0 0 280px;">
   <script> 
  cont = new scroll();
  cont.name = "cont";
  cont.height = 18;
  cont.width = 330;
  cont.scrollspeed = 20;
  cont.pausedelay = 3000;
  cont.pausemouseover = true;

     cont.add("<span style='color:#898989'>우리가족 행복하게 건강하게!아빠 사업도 대박나라!^^</span>");

     cont.add("<span style='color:#898989'>대학생활 마지막 생일 >ㅁ<  취업잘되게 해주세요</span>");

     cont.add("<span style='color:#898989'>제발 남자친구 생기게 해주세요 !</span>");

     cont.add("<span style='color:#898989'>우리가족 다 건강하길...ㅎㅎ</span>");

     cont.add("<span style='color:#898989'>가족 모~두 건강하길..정말 건강이 최고!! ^-^</span>");

     cont.add("<span style='color:#898989'>20살의 마지막..사랑하는사람에게 프로포즈받을수있길~</span>");

     cont.add("<span style='color:#898989'>마지막 생일</span>");

     cont.add("<span style='color:#898989'>이번에 취업되게 신이시여~~~~도와주서소~~!!!!!!</span>");

     cont.add("<span style='color:#898989'>이번 생일은 가족과 함께 ~</span>");

     cont.add("<span style='color:#898989'>이번달 생일 꼭 서프라이즈하게 보내고 싶어요!!!!!</span>");

    cont.start();
   </script>
   </div>