简体   繁体   English

切换脚本和按钮不起作用

[英]A toggle script and a button that doesn't work

I realize there a hundreds of threads around toggle scripts and I have been searching and looking for over a week now. 我意识到围绕切换脚本有数百个线程,而我一直在寻找和寻找一个多星期。 I do use one and it works but only partly. 我确实使用了一种,但它只能部分起作用。 It does toggle hide and show on the object it's supposed to but the button is the major problem here, at least I think it is! 它确实可以在应该隐藏的对象上切换隐藏和显示,但是按钮是这里的主要问题,至少我认为是这样! I want the button to always stay the the bottom of the page or be down when no toggle is open and follow the toggle up with it is clicked to open. 我希望按钮始终保持在页面底部或在没有打开任何拨动开关的情况下保持向下,然后单击向上的拨动开关并单击打开。

Right now the button is at the top when the toggle is closed and at the bottom when the toggle is open. 现在,当开关关闭时,按钮在顶部,当开关打开时,按钮在底部。

This is the script I'm using at the moment 这是我目前正在使用的脚本

<script>
    var toggle = function() {
    var mydiv = document.getElementById('toggle-footer');
        if (mydiv.style.display === 'block' || mydiv.style.display === '')
            mydiv.style.display = 'none';
        else
            mydiv.style.display = 'block'
                            }
</script>

And this is the button to the toggle 这是切换按钮

<center><div type="submit" class="togglebtn" onclick="toggle();">Meny</div></center>

All this is supposed to toggle this part. 所有这些都应该切换到这一部分。 The display: none; 显示:无; is there because otherwise the part I want to toggle is there from the start when i want it to be hidden from the start. 之所以存在,是因为否则当我希望从一开始就隐藏它时,我想切换的部分就会从一开始就存在。

<div id="toggle-footer" style="display:none;"> <!-- Beginning toggle-footer -->
<div class="container"> <!-- Beginning container -->
and some content in here
</div> <!-- End container-->
</div> <!-- End band-toggle -->

If it's to any use there is the CSS code for the button itself. 如果有任何用途,则按钮本身具有CSS代码。 I have tried to fixate it but that doesn't work. 我已尝试修复它,但这不起作用。 When I place the button above the toggle div it stays put but that also means it stays on the top of the page when I want it at the bottom. 当我将按钮放置在切换div上方时,它会保持放置状态,但这也意味着当我希望它位于页面底部时,它仍位于页面顶部。

CSS 的CSS

.togglebtn {
-moz-box-shadow:inset 0px 1px 0px 0px #ffffff;
-webkit-box-shadow:inset 0px 1px 0px 0px #ffffff;
box-shadow:inset 0px 1px 0px 0px #ffffff;
background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #ededed), color-stop(1, #dfdfdf) );
background:-moz-linear-gradient( center top, #ededed 5%, #dfdfdf 100% );
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ededed', endColorstr='#dfdfdf');
background-color:#ededed;
-webkit-border-top-left-radius:15px;
-moz-border-radius-topleft:15px;
border-top-left-radius:15px;
-webkit-border-top-right-radius:15px;
-moz-border-radius-topright:15px;
border-top-right-radius:15px;
-webkit-border-bottom-right-radius:0px;
-moz-border-radius-bottomright:0px;
border-bottom-right-radius:0px;
-webkit-border-bottom-left-radius:0px;
-moz-border-radius-bottomleft:0px;
border-bottom-left-radius:0px;
text-indent:0;
border:1px solid #dcdcdc;
display:inline-block;
color:#777777;
font-family:Arial;
font-size:15px;
font-weight:normal;
font-style:normal;
height:23px;
line-height:23px;
width:75px;
text-decoration:none;
text-align:center;
text-shadow:1px 1px 0px #ffffff;
position: static;
bottom: 0xp;

}
.togglebtn:hover {
background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #dfdfdf), color-stop(1, #ededed) );
background:-moz-linear-gradient( center top, #dfdfdf 5%, #ededed 100% );
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#dfdfdf', endColorstr='#ededed');
background-color:#dfdfdf;
}.togglebtn:active {
position:relative;
top:1px;

What am I doing wrong or is there another solution to my problem. 我做错了什么,还是有其他解决方案来解决我的问题。 I'm a beginner at this and all I know is self-learned. 我是一个初学者,我所知道的都是自学的。 Well I'm hoping for the best anyway, thank you for taking the time to read this. 好吧,无论如何,我都希望是最好的,感谢您抽出宝贵的时间阅读本文。

If you want the button to be stable, change it's position from static to either absolute or fixed . 如果您希望按钮稳定,请将其位置从static更改为absolutefixed

position:static elements are in the normal flow of the page, so it might change position when the page layout changes. position:static元素位于页面的正常流程中,因此当页面布局更改时,它可能会更改位置。

position:fixed elements are positioned relative to the window. position:fixed元素相对于窗口定位。 Even if you scroll the page fixed positioned elements will stay where it is. 即使滚动页面, fixed位置的元素也将保留在原处。

absolute positioned elements will be positioned relative to the first parent having position other than static absolute定位的元素将相对于具有非static位置的第一个父元素定位

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

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