我的第一篇开源码

说起来真的让人脸红,这个是我的第一个上传到网络上的代码,按理说应该写的漂亮、大体一些,然而,这些都没有达到。甚至,这段代码都不完全是我自己想出来的。不过,没办法,谁让我是一个刚刚出来的小菜鸟呢。

功能简介:这个小东西,是基于js初级、DOM基础用而写出的一个点击按钮,切换图片的功能。

个人想法拓展:基于这个功能,我想到网络上的轮播图中,点击左、右两个透明度在0.2-0.5之间的图片,就可以切换轮播图中的图片。只不过是将此案例中的---按钮-->图片而已。

或许在后续的学习中,我会发现并不是这样,那就到时候再说吧。

PS:我发现我还不会用这个开元网站,崩溃。。。我想,下一次上传代码时,我应该已经会用这个开源网站了。

<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <meta name="Generator" content="EditPlus®">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
  <title>图片切换</title>
  <style>
    img{
        width:200px;
        height:100px;
    }
  </style>
 </head>
 <body>
    <img src="icon_1.png" id="icon"><br>
    <button id="prev">上一张</button>
    <button id="next">下一张</button>
<script>
        window.οnlοad=function(){
            var icon=document.getElementById("icon");
            var prev=document.getElementById("prev");
            var next=document.getElementById("next");
            var maxIndex=4,minIndex=1,currentIndex=minIndex;
            prev.οnclick=function(){
               // alert("点击的上一张");
                   if(currentIndex==minIndex){
                        currentIndex=maxIndex;
                   }else{
                        currentIndex--;
                   }
                   icon.setAttribute("src","icon_"+currentIndex+".png");
            };

            next.οnclick=function(){
                if(currentIndex==maxIndex){
                    currentIndex=minIndex;
                }else{
                    currentIndex++;
                }
                icon.setAttribute("src","icon_"+currentIndex+".png");
            }
        }
</script>
 </body>
</html>

转载于:https://my.oschina.net/u/3893964/blog/1844752

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值