这篇文章主要介绍了关于js实现简单的单击图片循环播放,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下
简单的单击图片循环播放:
<!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>
以上就是本文的全部内容,希望对大家的学习有所帮助,更多相关内容请关注!
相关推荐:
javascript中getter和setter的介绍
用jquery实现简单九宫格抽奖
js实现点击按钮可实现编辑
以上就是js实现简单的单击图片循环播放的详细内容。