单击箭头按钮时如何切换(开/关)夏季
我面临着与我想要的切换有关的问题,当我单击任何箭头BTN时,只有单击的BTN摘要将显示。我尝试了很多,但仍处于问题方面。我使用了不透明度:0;而不是显示:无;段落。对不起!我在学习区并从事一些小型项目。感谢您的支持。
<section>
<div class="content">
<h3>How does it work?</h3>
<i id="uparrow" class="fa fa-angle-up"></i>
</div>
<p id="para">Lorem ipsum dolor sit amet consectetur, adipisicing elit. Sequi provident ut sed
eaque earum
commodi consectetur iandae magnam nostrum gendi veniam voluptate beatae. Non soluta
reprehenderit quas dicta?</p>
</section>
<section>...</section>
<section>...</section>
<section>...</section>
<script>
const arrow = document.querySelectorAll('#uparrow');
const para = document.querySelectorAll('#para');
const content = document.getElementsByClassName('content');
for(let i=0; i<arrow.length; i++){
arrow.addEventListener('click',()=>{
closeAll();
openQuest(i);
})
}
function openQuest(i){
para[i].style.opacity = '1';
para[i].style.maxHeight = '10rem';
arrow[i].style.transform = 'rotateX(180deg)';
}
function closeAll(){
for(let i=0; i<content.length; i++){
arrow[i].style.transform = 'rotateX(0deg)';
para[i].style.maxHeight = '0rem';
para[i].style.opacity = '0';
}
}
</script>
I am facing an issue related to the toggle which I want, when I click on any arrow btn, only the clicked btn summary will display. I have tried a lot but am still on the problem side. I have used opacity: 0; instead of display: none; for a paragraph. Sorry! I am in a learning zone and working on some small projects. Thanks for your support.
<section>
<div class="content">
<h3>How does it work?</h3>
<i id="uparrow" class="fa fa-angle-up"></i>
</div>
<p id="para">Lorem ipsum dolor sit amet consectetur, adipisicing elit. Sequi provident ut sed
eaque earum
commodi consectetur iandae magnam nostrum gendi veniam voluptate beatae. Non soluta
reprehenderit quas dicta?</p>
</section>
<section>...</section>
<section>...</section>
<section>...</section>
<script>
const arrow = document.querySelectorAll('#uparrow');
const para = document.querySelectorAll('#para');
const content = document.getElementsByClassName('content');
for(let i=0; i<arrow.length; i++){
arrow.addEventListener('click',()=>{
closeAll();
openQuest(i);
})
}
function openQuest(i){
para[i].style.opacity = '1';
para[i].style.maxHeight = '10rem';
arrow[i].style.transform = 'rotateX(180deg)';
}
function closeAll(){
for(let i=0; i<content.length; i++){
arrow[i].style.transform = 'rotateX(0deg)';
para[i].style.maxHeight = '0rem';
para[i].style.opacity = '0';
}
}
</script>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您为什么不使用
&lt;详细信息&gt;
标签?Why dont you use the
<details>
tag?