有更好的展示和隐藏方式吗

Is there a better way to show and hide?

本文关键字:隐藏 方式吗 更好      更新时间:2023-09-26

好的,所以我想从隐藏的页面内部显示一个div,当点击它时,它适合页面的1005宽度和滚动内容的100%高度,即使经过广泛的z索引检查和设置,我也会遇到一些背景内容的问题,以及向下滚动时的问题,一旦你到达div的底部,它似乎会向下滚动并显示它下面的内容,而我真的不想让它这样做。我想知道是否有比使用我现有的内容更具吸引力、结构化或更高效的东西。这里的编码任何建议都将不胜感激。

    <script type="text/javascript">
<!--
    function toggle_visibility(id) {
       var e = document.getElementById(id);
       if(e.style.display == 'block')
          e.style.display = 'none';
       else
          e.style.display = 'block';
    }
//-->
</script>

<div id="ef" style="display:none; width:100%; height:120%; overflow:scroll; background-color:#f1f1f1; -webkit-overflow-scrolling:touch; z-index:2000; padding-top:43px; "><div id="efmenubars">
            <div style="width:50px; height:40px;margin-top:7px; float:left; margin-left:8px;">
            </div><span style="display:inline-block;  text-align:center; font-family:'helvetica_bqregular'; font-size:20px; color:#333;">Post Enquiry</span>
    <a href="#" onclick="toggle_visibility('ef');"> <img src="../images/close.png" width="50px" style="float:right; margin-top:7px; margin-right:8px;" /></a>
        </div>
<p>{leftcol}</p></div>
<a class="button2" style="float:right; margin-right:12px; margin-top:19px;"  onclick="toggle_visibility('ef');">Post Enquiry</a>

希望这一切都有意义,很抱歉内联css非常令人困惑,我知道这是一项需要清理的快速工作。

干杯

Ol

只需使用jquery在可见性状态之间切换即可。jQuery主要用于简化和增强代码。因此,如果您真的想改进代码,请使用jquery。

.$('#idOfYorElement').toggle();

只是一个简单的一行:(