2012年10月13日土曜日

開発環境

『初めてのJavaScript 第2版』(シェリー・パワーズ著(Shelley Powers著)、武舎 広幸+武舎 るみ訳、オライリー・ジャパン、2009年、ISBN978-4-84311-425-5) の9章(ブラウザオブジェクトモデル)練習問第9-3を解いてみる。

その他参考書籍

9-3.

コード(TextWrangler)

<script>
var pics = [
  "https://lh3.googleusercontent.com/-H1qSm9HBU5I/TCMQP4fQkjI/AAAAAAAAASg/OqQ1IoOzyPo/w313-h313-n-k/drawing.png",
  "https://lh5.googleusercontent.com/-v4VAVnmZVnE/TCQApWOL2OI/AAAAAAAAASo/RnGOPXDN_lk/w314-h313-n-k/drawing.png",
  "https://lh4.googleusercontent.com/-qcMiQALD_6Y/TCR80SUS8SI/AAAAAAAAASw/5-dA2gueWeA/w314-h313-n-k/drawing.png",
  "https://lh4.googleusercontent.com/-AoRXaUWIPSw/TCLAkE-9fJI/AAAAAAAAASY/HeXZPX1fWaI/w297-h296-n-k/drawing.png",
  "https://lh6.googleusercontent.com/-3bQfrwaWNFk/TCSzl4EG72I/AAAAAAAAAS4/OMlEbpFjIVk/w314-h313-n-k/drawing.png"
  ];
var currentPhoto = 0;
function changePhoto(photo){
  $('#img0').attr('src',pics[photo]);
}
function nextPic(){
  if(currentPhoto < pics.length){
    changePhoto(currentPhoto);
    currentPhoto += 1;
  } else {
    currentPhoto = 0;
    changePhoto(currentPhoto);
    currentPhoto += 1;
  }
}
var tmOut;
function start(){
  tmOut = setInterval(function(){
    nextPic();
  } ,5000);
}
function stop(){
  clearInterval(tmOut);
}
</script>
<input type="button" value="start" onclick="start()">
<input type="button" value="stop" onclick="stop()"><br />
<img id="img0" />

0 コメント:

コメントを投稿