我想按下面三个图标切换上面的图片怎么用JS做

2022-04-11 综合 54阅读
html>    
    
    
    鼠标移动到按钮上,显示对应图片    
        
        
      
*{    
margin: 0;    
padding: 0;    
}    
ul{    
list-style: none;    
}    
a{    
text-decoration: none;    
}    
.main{    
position: relative;    
width: 720px;    
height: 340px;    
margin: 100px auto 0;    
}    
.pic{    
position: relative;    
}    
.pic a img{    
width: 720px;    
height: 340px;    
position: absolute;    
display: none;    
}    
.btn{    
width: 160px;    
height: 20px;    
position: absolute;    
bottom: 10px;    
left: 280px;    
background: #6C6666;    
border-radius: 10px;    
opacity: 0.8;    
}    
.btn ul li{    
float: left;
    
}    
.btn ul li{    
margin: 2.5px 2.5px;    
width: 15px;    
height: 15px;    
background: #fff;    
text-align: center;    
border-radius: 7.5px;    
cursor: pointer;/*鼠标指针变成小手*/
    
}    
.btn .on{    
background: #db192a;    
}    
    
        
$(function(){    
 $("div.btn ul li").hover(function(){    
   var index = $(this).index();    
$(this).addClass("on").siblings().removeClass("on");    
$("div.pic img").stop(true).fadeOut();    
   $("div.pic img").eq(index).stop(true).fadeIn();    
    
 },function(){    
 })    
    
})    
       
        
       
       
       
        
          
            
            
            
            
            
            
            
            
          
          
        
        
              
  •     
              
  •     
              
  •     
              
  •     
              
  •     
              
  •     
              
  •     
              
  •     
            
    
          
        
         
       

自己改一下图片的路径就可以了。

要想改变按钮的样式,自己可以根据需要修改。

我的是鼠标移动上去就改变图片,你也可以自己改成点击事件

声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com