简体   繁体   English

向 div 打开和关闭添加一个三角形图标

[英]add a triangle icon to the div opening and closing

I have the code where onclick of the link, i am opening and closing the div我有点击链接的代码,我正在打开和关闭 div

here is the code这是代码

<div id="opendialog" style="display:none;">
      <div style="width:100%;height:200px;background:grey;"></div>
    </div>

the function功能

function openx() {
      var x= document.getElementById("opendialog");
      if (x.style.display === "none") {
        x.style.display = "block";
      } else {
        x.style.display = "none";
      }
    }

it works well but how can i add a traingle to the link when clicked it should show a traingle to the div, trying in a way that if the screen is small or bigger, the traingle should be placed properly under the link when clicked and should not be a problem它工作得很好,但是我如何在单击时向链接添加一个 traingle 它应该向 div 显示一个 traingle,尝试以一种方式,如果屏幕很小或更大,则应该在单击时将 traingle 正确放置在链接下并且应该不成问题

here is the html i have这是我的 html

<div onclick="openx()">+ Add <div>

You can use font-awesome icon for triangle up and down.您可以使用 font-awesome 图标来上下三角形。 You just need to add and remove class accordingly.您只需要相应地添加和删除类。

 function openx() { var x= document.getElementById("opendialog"); if (x.style.display === "none") { x.style.display = "block"; document.getElementById("myIcon").innerHTML = "➖"; } else { document.getElementById("myIcon").innerHTML = "➕"; x.style.display = "none"; } }
 #myIcon { margin-bottom: 3px; font-size: 20px; font-weight: bolder; } #myIcon:hover { cursor: pointer; }
 <div onclick="openx()"><div id="myIcon">➕</div><div> <div id="opendialog" style="display:none;"> <div style="width:100%;height:200px;background:grey;"></div> </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM