javascript 通过 jquery css 底部和顶部更改一次
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6498290/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Change by jquery css bottom & top more once
提问by Andriy K.
Is it something wrong or jquery bug?
是出了什么问题还是jquery错误?
So we have such code for example and in third click the layer don't change to bottomagain..
例如,我们有这样的代码,在第三次单击时,图层不会再次更改为底部..
<style type="text/css">
#menu1 {
width:100%;
height:32px;
overflow:hidden;
background:#ff0033;
position:fixed;
left:0px;
cursor:pointer;
bottom:174px;
}
#content1 {
position:fixed;
width:100%;
left:0;
overflow:auto;
background:blue;
height:200px;
bottom:300px;
}
</style>
<script type="text/javascript" src="js/jquery-1.6.1.min.js"></script>
<script type="text/javascript">
$(function(){
var click1=0;
$("#menu1").click(function () {
if (click1==0) {
$("#content1").css({ bottom: "250px", display: "block", position: "fixed" });
click1 = 1;
} else {
$("#content1").css({ top: "100px", "display": "block", display: "block", position: "fixed" });
click1 = 0;
}
});
});
</script>
回答by Mark Kahn
if you have both top
and bottom
set you have issues in that they either both get applied (and height is calculated), or if a height is set, only top
gets applied. So you need to wipe the ones you're not using:
如果您同时拥有top
并bottom
设置了您的问题,因为它们要么都被应用(并且计算了高度),或者如果设置了高度,则仅top
被应用。所以你需要擦掉那些你不使用的:
{ bottom: 250, top: 'auto' }
{ top: 100, bottom: 'auto' }