时间:2021-07-01 10:21:17 帮助过:9人阅读
简单的单击图片循环播放:
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <meta http-equiv="X-UA-Compatible" content="ie=edge">
- <title>Document</title>
- </head>
- <body>
- <img src="imges/01.jpg" alt="" id='img'>
- <button id='prev'>上一张</button>
- <button id='next'>下一张</button>
- </body>
- <script>
- window.onload = function(){ //获取要用到的元素,标签
- var img = document.getElementById('img'); var prev = document.getElementById('prev'); var next = document.getElementById('next'); //定义两端的临界值, 定义活动的变量 最大5张、
- var maxIndex = 5; var minIndex = 1; var activeIndex = minIndex;
- // 确定事件源 绑定事件函数。
- prev.onclick = function(){ //当点击 上一张的时候, img的src 实现切换
- img.src = 'imges/0' + activeIndex + '.jpg';
- if(activeIndex === 1){
- activeIndex = 5;
- }else{activeIndex --;}
- }
- next.onclick = function(){
- if(activeIndex === 5){
- activeIndex = 1;
- }else{
- activeIndex++;
- }
- img.src = 'imges/0' + activeIndex + '.jpg';
- }
- }
- </script>
- </html>
以上就是本文的全部内容,希望对大家的学习有所帮助,更多相关内容请关注PHP中文网!
相关推荐:
JavaScript中getter和setter的介绍
用jQuery实现简单九宫格抽奖
js实现点击按钮可实现编辑
以上就是js实现简单的单击图片循环播放的详细内容,更多请关注Gxl网其它相关文章!