[英]css html div moving to left not working correctly
我的html代碼
<body>
<div id="head-title">
<div id="box">
<a href="#" id="divhide">
<div>
<div class="whiteline"></div>
<div class="whiteline"></div>
<div class="whiteline"></div>
</div>
</a>
</div>
</div>
<div id="nav">
<?php echo $menu_item?>
</div>
<div id="main">
</div>
</body>
的CSS
body
{
margin:0px;
}
#head-title
{
height: 65px;
width: 100%;
background-color: #E67817;
}
#nav
{
float:left;
width:100px;
height:100%;
background: #1e293d;
color: #465269;
}
#main
{
float:left;
width:100%;
height:100%;
}
#box
{
position:absolute;
left:30px;
top:14px;
width:50px;
height:50px;
}
.whiteline
{
margin-top:5px;
border:2px solid white;
width:25px;
}
我使用jQuery將div #nav向左移動
<script>
flag= true;
$('#divhide').click(function()
{
if(flag)
{
$("#nav").css("marginLeft","0px").animate(
{
marginLeft: "-100"
}, 1000);
flag = false;
}
else
{
$("#nav").css("marginLeft","-100px").animate(
{
marginLeft: "=0"
}, 1000);
flag = true;
}
});
</script>
但是當div #nav向左移動時,右側#main上的div不會向左移動。 和div #nav無法正確到達原始位置,即在1秒內沒有出現,當我單擊div時,它不會像感覺那樣移動。 有什么建議么 ?
您應該更新您的JavaScript
marginLeft: "-100"
作為marginLeft: "-100px"
, marginLeft: "=0"
應為marginLeft: "0"
如果仍然“不起作用”,則表示導航的高度等於0 ...出於測試目的,嘗試將height:100%
更新為height:100px
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.