试图在Javascript中创建简单的幻灯片放映方法

时间:2011-11-24 23:29:05

标签: javascript

我一直在努力创建一个基本的JavaScript剪辑,以便在点击链接时在网页上前后滑动图片。

以下是我在网页<head>部分的js代码:

<script type="text/javascript">

   //if browser does noe support getElementbyId then exit
   var step = 1;
   if ( !document.getElementById ) {
       return;
   }
   var src = 'images/gallery_images/image'+step+'.jpg';
   document.getElementById('photos').src = src;

   function slideForward()
   {
        //files are named as image1, image2....
        step++;
        var src = 'images/gallery_images/image'+step+'.jpg';
        document.getElementById('photos').src = src;
   }

   function slideBack()
   {
       step--;
       var src = 'images/gallery_images/image'+step'.jpg';
       document.getElementById('photos').src = src;
   }
</script>

我绑定了2个函数,使用onclick在标记中向后移动:

<a onclick="slideBack()">
    <img src="images/gallery_06.jpg" alt="" name="left" width="26" height="90" id="gallery_06" />
</a>
<a onclick="slideForward()">
    <img src="images/gallery_07.jpg" alt="" name="right" width="27" height="90" id="gallery_07" />
</a>

有关我遗失的任何建议吗?什么都没有归还。

0 个答案:

没有答案