Doge log

Abby CTO 雑賀 力王のオフィシャルサイトです

ある要素を点滅させる

帰りの電車の中でvalidatorのエラー処理をどうするかで書いてみたコードを晒す。
役に立ったと思う人はコメント残すように!
(嘘です)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
<script language="JavaScript" type="text/javascript" src="../js/kumu/kumu.js"></script>
<script>
var effect = {
  light : false,
  self : null,
  element : null,
  
  setElement : function(e){
    if(this.element){
      return;
    }
    this.element = e;
  },
  
  highlight : function(name){
    return function(){
      var e = $n(name);
      this.setElement(e[0]);
      if(this.light){
       this.element.style.background = '#C00';
       this.light = false;
      }else{
       this.element.style.background = '#ffa';
        this.light = true;
      }
    }
  },
  
  start : function(name){ 
    this.self = setInterval(this.highlight(name).bindScope(this), 500);
  },
  
  end : function(){ 
    clearInterval(this.self);
    this.self = null;
    this.element.style.background = '#ffffff';
  }
}  
</script>

<title>Insert title here</title>
</head>
<body>
<input tyep="text" name="test" value="" />
<input type="button" name="" value="start" onclick="effect.start('test')">
<input type="button" name="" value="end" onclick="effect.end()">

</body>
</html>

めんどいので単純に背景色変えるだけにしよう。
おかげで電車おりそこねそうになったし。
実は電車ん中ぐらいでしかコード書けてないのはここだけの秘密だったりする。
うくく。