电脑知识|欧美黑人一区二区三区|软件|欧美黑人一级爽快片淫片高清|系统|欧美黑人狂野猛交老妇|数据库|服务器|编程开发|网络运营|知识问答|技术教程文章 - 好吧啦网

您的位置:首頁技術文章
文章詳情頁

基于JavaScript實現輪播圖效果

瀏覽:35日期:2023-06-11 13:01:56

本文實例為大家分享了JavaScript實現輪播圖效果的具體代碼,供大家參考,具體內容如下

學習筆記(學校的課設),實現了左右切換,按指示點切換、按小圖標切換和自動切換,但是還有某些功能沒完善,如:切換到某張圖片后,左右并沒有切換到前后相應的圖片。

先看實現效果:

基于JavaScript實現輪播圖效果

代碼僅供參考:

<!DOCTYPE html><html> <head> <meta charset='UTF-8'> <title></title> <style> .div0{ height: 100px; width: 100%; background-color:black; opacity:0.75; } .div1{ background-image: url(img/bg2.png); height: 400px; width: 100%; } .div2{ height: 200px; width: 100%; background-color:black; opacity:0.75; position: absolute; } .spot{ position: absolute; left: 10%; } .spot_list1{ float: left; border:3px solid wheat; transform:rotate(-30deg); -ms-transform:rotate(-30deg); -moz-transform:rotate(-30deg); -webkit-transform:rotate(-30deg); -o-transform:rotate(-30deg); opacity:0.5; } .spot_list2{ float: left; border:3px solid wheat; transform:rotate(-15deg); -ms-transform:rotate(-15deg); -moz-transform:rotate(-15deg); -webkit-transform:rotate(-15deg); -o-transform:rotate(-15deg); opacity:0.5; } .spot_list3{ float: left; border:3px solid wheat; transform:rotate(28deg); -ms-transform:rotate(28deg); -moz-transform:rotate(28deg); -webkit-transform:rotate(28deg); -o-transform:rotate(28deg); opacity:0.5; } .div1_1{ border: 10px solid gainsboro; width: 830px; height: 300px; left: 10%; top: 10%; position: relative; overflow: hidden; } .btn { width: 100%; height: 80px; position: absolute; margin: 0 auto; top: 120px; } .box_big { position: absolute; height: 400px; vertical-align: middle } #imgList{ list-style: none; position: absolute; } #imgList li{ float: left; margin: 0 10px; } .left_btn, .right_btn { width: 30px; height: 80px; background:gray; line-height: 90px; border-radius: 10px; } .left_btn { float: left; } .right_btn { float: right; } #navDiv{ position: absolute; left: 300px; } #navDiv a{ float: left; width: 15px; height: 15px; border-radius:50%; background-color: black; margin: 0 10px; opacity: 0.5; filter: alpha(opacity=50); } #navDiv a:hover{ background-color: red; } </style> </head> <body> <div class='div0'></div> <div class='div1'> <div class='div1_1'> <div id='navDiv'> <a href='javascript:;' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' ></a> <a href='javascript:;' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' ></a> <a href='javascript:;' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' ></a> <a href='javascript:;' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' ></a> <a href='javascript:;' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' ></a> <a href='javascript:;' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' rel='external nofollow' ></a> </div> <div class='box_big'> <ul id='imgList'> <li><img src='http://www.hdgsjgj.cn/bcjs/img/1.jpg' ></li> <li><img src='http://www.hdgsjgj.cn/bcjs/img/2.jpg' id='2></li> <li><img src='http://www.hdgsjgj.cn/bcjs/img/3.jpg' /></li> <li><img src='http://www.hdgsjgj.cn/bcjs/img/4.jpg' /></li> <li><img src='http://www.hdgsjgj.cn/bcjs/img/5.jpg' /></li> <li><img src='http://www.hdgsjgj.cn/bcjs/img/6.jpg' /></li> </ul> </div> <div class='btn'> <div class='left_btn'><img src='http://www.hdgsjgj.cn/bcjs/img/prev.png'></div> <div class='right_btn'><img src='http://www.hdgsjgj.cn/bcjs/img/next.png'></div> </div> </div> </div> <!--小標圖片--> <div onmouseleave='m1()'> <div class='spot'> <img src='http://www.hdgsjgj.cn/bcjs/img/thumbs/1.jpg' onmouseover='mouseover(1)' onmouseout='mouseout(1)'> <img src='http://www.hdgsjgj.cn/bcjs/img/thumbs/2.jpg' onmouseover='mouseover(2)' onmouseout='mouseout(2)'> <img src='http://www.hdgsjgj.cn/bcjs/img/thumbs/3.jpg' onmouseover='mouseover(3)' onmouseout='mouseout(3)'> <img src='http://www.hdgsjgj.cn/bcjs/img/thumbs/4.jpg' onmouseover='mouseover(4)' onmouseout='mouseout(4)'> <img src='http://www.hdgsjgj.cn/bcjs/img/thumbs/5.jpg' onmouseover='mouseover(5)' onmouseout='mouseout(5)'> <img src='http://www.hdgsjgj.cn/bcjs/img/thumbs/6.jpg' onmouseover='mouseover(6)' onmouseout='mouseout(6)'> </div> </div> </body> <script> var box=document.getElementById('1'); //var spot = document.getElementsByClassName('spot_list'); var left_btn=document.getElementsByClassName('left_btn')[0]; var right_btn=document.getElementsByClassName('right_btn')[0]; var time = null; var count = 0; var ids=document.getElementsByTagName('a'); ids[0].style.backgroundColor='red'; var spot_list1=document.getElementById('spot_list1'); spot_list1.setAttribute('class','spot_list3'); spot_list1.style.opacity='0.98'; //左按鈕 left_btn.onclick=function(){ count--; if(count<1){ count=6 } box.src='http://www.hdgsjgj.cn/bcjs/img/' + count + '.jpg'; for(var i=0;i<ids.length;i++){ ids[i].style.backgroundColor='black'; } ids[count - 1].style.backgroundColor='red'; for(var i=1;i<=6;i++){ var img=document.getElementById('spot_list'+i); if(img.id=='spot_list1' || img.id=='spot_list4'){ img.setAttribute('class','spot_list1'); img.style.opacity='0.5'; }else if(img.id=='spot_list2' || img.id=='spot_list5'){ img.setAttribute('class','spot_list2'); img.style.opacity='0.5'; }else if(img.id=='spot_list3' || img.id=='spot_list6'){ img.setAttribute('class','spot_list3'); img.style.opacity='0.5'; } } var img=document.getElementById('spot_list'+count); if(img.id=='spot_list1' || img.id=='spot_list4'){ img.setAttribute('class','spot_list3'); img.style.opacity='0.98'; }else if(img.id=='spot_list2' || img.id=='spot_list5'){ img.setAttribute('class','spot_list3'); img.style.opacity='0.98'; }else if(img.id=='spot_list3' || img.id=='spot_list6'){ img.setAttribute('class','spot_list1'); img.style.opacity='0.98'; } } //右按鈕 right_btn.onclick=function(){ changeImg(); } // var x=1; var changeImg = function(){ x++; if(x > 6){ x = 1; } box.src = 'http://www.hdgsjgj.cn/bcjs/img/' + x + '.jpg'; for(var i=0;i<ids.length;i++){ ids[i].style.backgroundColor='black'; } ids[x - 1].style.backgroundColor='red'; for(var i=1;i<=6;i++){ var img=document.getElementById('spot_list'+i); if(img.id=='spot_list1' || img.id=='spot_list4'){ img.setAttribute('class','spot_list1'); img.style.opacity='0.5'; }else if(img.id=='spot_list2' || img.id=='spot_list5'){ img.setAttribute('class','spot_list2'); img.style.opacity='0.5'; }else if(img.id=='spot_list3' || img.id=='spot_list6'){ img.setAttribute('class','spot_list3'); img.style.opacity='0.5'; } } var img=document.getElementById('spot_list'+x); if(img.id=='spot_list1' || img.id=='spot_list4'){ img.setAttribute('class','spot_list3'); img.style.opacity='0.98'; }else if(img.id=='spot_list2' || img.id=='spot_list5'){ img.setAttribute('class','spot_list3'); img.style.opacity='0.98'; }else if(img.id=='spot_list3' || img.id=='spot_list6'){ img.setAttribute('class','spot_list1'); img.style.opacity='0.98'; } } //設置計時器 var show; show=setInterval(changeImg, 3000); //圖片切換 function mouseover(n){ clearInterval(show); var img=document.getElementById('spot_list'+n); if(img.id=='spot_list1' || img.id=='spot_list4'){ img.setAttribute('class','spot_list3'); img.style.opacity='0.98'; }else if(img.id=='spot_list2' || img.id=='spot_list5'){ img.setAttribute('class','spot_list3'); img.style.opacity='0.98'; }else if(img.id=='spot_list3' || img.id=='spot_list6'){ img.setAttribute('class','spot_list1'); img.style.opacity='0.98'; } box.src='http://www.hdgsjgj.cn/bcjs/img/'+n+'.jpg'; for(var i=0;i<ids.length;i++){ ids[i].style.backgroundColor='black'; } ids[n-1].style.backgroundColor='red'; } for(let i=0;i<ids.length;i++){ ids[i].onclick=function(){ clearInterval(show); for(var n=0;n<ids.length;n++){ ids[n].style.backgroundColor='black'; } box.src='http://www.hdgsjgj.cn/bcjs/img/'+(i+1)+'.jpg'; ids[i].style.backgroundColor='red'; } } //離開小圖標時 function mouseout(n){ var img=document.getElementById('spot_list'+n); ids[n-1].style.backgroundColor='black'; if(img.id=='spot_list1' || img.id=='spot_list4'){ img.setAttribute('class','spot_list1'); img.style.opacity='0.5'; }else if(img.id=='spot_list2' || img.id=='spot_list5'){ img.setAttribute('class','spot_list2'); img.style.opacity='0.5'; }else if(img.id=='spot_list3' || img.id=='spot_list6'){ img.setAttribute('class','spot_list3'); img.style.opacity='0.5'; } } function m1(){ //啟動計時器 show=setInterval(changeImg, 3000); } </script></html>

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: JavaScript
相關文章:
主站蜘蛛池模板: 冷却塔减速机器_冷却塔皮带箱维修厂家_凉水塔风机电机更换-广东康明冷却塔厂家 | 胶原检测试剂盒,弹性蛋白检测试剂盒,类克ELISA试剂盒,阿达木单抗ELISA试剂盒-北京群晓科苑生物技术有限公司 | 全自动端子机|刺破式端子压接机|全自动双头沾锡机|全自动插胶壳端子机-东莞市傅氏兄弟机械设备有限公司 | 活性氧化铝球|氧化铝干燥剂|分子筛干燥剂|氢氧化铝粉-淄博同心材料有限公司 | 臻知网大型互动问答社区-你的问题将在这里得到解答!-无锡据风网络科技有限公司 | 奇酷教育-Python培训|UI培训|WEB大前端培训|Unity3D培训|HTML5培训|人工智能培训|JAVA开发的教育品牌 | 胜为光纤光缆_光纤跳线_单模尾纤_光纤收发器_ODF光纤配线架厂家直销_北京睿创胜为科技有限公司 - 北京睿创胜为科技有限公司 | 圣才学习网-考研考证学习平台,提供万种考研考证电子书、题库、视频课程等考试资料 | 破碎机锤头_耐磨锤头_合金锤头-鼎成机械一站式耐磨铸件定制服务 微型驱动系统解决方案-深圳市兆威机电股份有限公司 | 字典-新华字典-在线字典查字-字典趣 | 无刷电机_直流无刷电机_行星减速机-佛山市藤尺机电设备有限公司 无菌检查集菌仪,微生物限度仪器-苏州长留仪器百科 | 鹤壁创新仪器公司-全自动量热仪,定硫仪,煤炭测硫仪,灰熔点测定仪,快速自动测氢仪,工业分析仪,煤质化验仪器 | 早报网| 气力输送_输送机械_自动化配料系统_负压吸送_制造主力军江苏高达智能装备有限公司! | 金刚网,金刚网窗纱,不锈钢网,金刚网厂家- 河北萨邦丝网制品有限公司 | 送料机_高速冲床送料机_NC伺服滚轮送料机厂家-东莞市久谐自动化设备有限公司 | 钛合金标准件-钛合金螺丝-钛管件-钛合金棒-钛合金板-钛合金锻件-宝鸡远航钛业有限公司 | 磁力抛光研磨机_超声波清洗机厂家_去毛刺设备-中锐达数控 | 温州富欧金属封头-不锈钢封头厂家 | 衡阳耐适防护科技有限公司——威仕盾焊接防护用品官网/焊工手套/焊接防护服/皮革防护手套 | 能量回馈_制动单元_电梯节能_能耗制动_深圳市合兴加能科技有限公司 | 电动车头盔厂家_赠品头盔_安全帽批发_山东摩托车头盔—临沂承福头盔 | 动力配电箱-不锈钢配电箱-高压开关柜-重庆宇轩机电设备有限公司 聚天冬氨酸,亚氨基二琥珀酸四钠,PASP,IDS - 远联化工 | 长沙中央空调维修,中央空调清洗维保,空气能热水工程,价格,公司就找维小保-湖南维小保环保科技有限公司 | 桂林腻子粉_内墙外墙抗裂砂浆腻子粉推荐广西鑫达涂料厂家供应 | 金属切削液-脱水防锈油-电火花机油-抗磨液压油-深圳市雨辰宏业科技发展有限公司 | 编织人生 - 权威手工编织网站,编织爱好者学习毛衣编织的门户网站,织毛衣就上编织人生网-编织人生 | 悬浮拼装地板_篮球场木地板翻新_运动木地板价格-上海越禾运动地板厂家 | 浙江栓钉_焊钉_剪力钉厂家批发_杭州八建五金制造有限公司 | BESWICK球阀,BESWICK接头,BURKERT膜片阀,美国SEL继电器-东莞市广联自动化科技有限公司 | 手机游戏_热门软件app下载_好玩的安卓游戏下载基地-吾爱下载站 | 10吨无线拉力计-2吨拉力计价格-上海佳宜电子科技有限公司 | 砖机托板价格|免烧砖托板|空心砖托板厂家_山东宏升砖机托板厂 | 媒介云-全网整合营销_成都新闻媒体发稿_软文发布平台 | 苏州工作服定做-工作服定制-工作服厂家网站-尺品服饰科技(苏州)有限公司 | 砂石生产线_石料生产线设备_制砂生产线设备价格_生产厂家-河南中誉鼎力智能装备有限公司 | 校园气象站_超声波气象站_农业气象站_雨量监测站_风途科技 | ETFE膜结构_PTFE膜结构_空间钢结构_膜结构_张拉膜_浙江萬豪空间结构集团有限公司 | 真空干燥烘箱_鼓风干燥箱 _高低温恒温恒湿试验箱_光照二氧化碳恒温培养箱-上海航佩仪器 | 心得体会网_心得体会格式范文模板 | 东莞螺丝|东莞螺丝厂|东莞不锈钢螺丝|东莞组合螺丝|东莞精密螺丝厂家-东莞利浩五金专业紧固件厂家 |