html5怎么产生手风琴效果,Html5 js实现手风琴效果

摘要:使用H5实现横向的手风琴功能html>

&nbs

使用H5实现横向的手风琴功能html>

* {

padding: 0;

margin: 0;

}

div {

width: 522px;

height: 222px;

margin: 50px auto;

border: 1px solid red;

box-sizing: border-box;

box-sizing: border-box;

}

ul {

overflow: hidden;

height: 222px;

}

li {

float: left;

height: 222px;

list-style: none;

box-sizing: border-box;

}

h3 {

width: 50px;

float: left;

height: 222px;

border: 1px solid green;

box-sizing: border-box;

}

img {

width: 0px;

float: left;

}

.img {

width: 220px;

}

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

var lis = document.querySelectorAll("li");

var imgs = document.querySelectorAll("img");

for(var i = 0; i 

//给所有的li标签添加点击事件

lis[i].onclick = function () {

//将所有的图片宽度设置为0

for(var i = 0; i 

imgs[i].style.width = "0px";

}

//将当前点击li标签中的img标签设置宽度为220px

this.querySelector("img").style.width = "220px";

}

}

更多关于Html5 js实现手风琴效果请关注PHP中文网(www.php.cn)其他文章!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
HTML 手风琴效果可以通过 CSS 实现。以下是一个简单的示例代码: ```html <!DOCTYPE html> <html> <head> <title>手风琴效果</title> <style> .container { width: 500px; margin: 0 auto; } .accordion { background-color: #eee; color: #444; cursor: pointer; padding: 18px; width: 100%; border: none; text-align: left; outline: none; font-size: 15px; transition: 0.4s; } .active, .accordion:hover { background-color: #ccc; } .panel { padding: 0 18px; background-color: white; display: none; overflow: hidden; } </style> </head> <body> <div class="container"> <button class="accordion">Section 1</button> <div class="panel"> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p> </div> <button class="accordion">Section 2</button> <div class="panel"> <p>Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.</p> </div> <button class="accordion">Section 3</button> <div class="panel"> <p>Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p> </div> </div> <script> var acc = document.getElementsByClassName("accordion"); var i; for (i = 0; i < acc.length; i++) { acc[i].addEventListener("click", function() { this.classList.toggle("active"); var panel = this.nextElementSibling; if (panel.style.display === "block") { panel.style.display = "none"; } else { panel.style.display = "block"; } }); } </script> </body> </html> ``` 在这个示例中,我们创建了一个容器 `.container`,内部有三个按钮 `.accordion` 和三个面板 `.panel`。点击按钮时,面板会展开或折叠。CSS 中使用了过渡效果,让切换更加平滑。JavaScript 代码用于给按钮添加点击事件,以切换面板的显示状态。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值