嘿,另一个有趣的是,
我正在构建一个菜单,该菜单将在页面的整个宽度(宽度:100%;)上滑动,并且需要一些帮助。我的页面右侧有一个箭头按钮,单击该按钮会触发菜单栏滑出。我希望箭头按钮在其前面滑出,并一路将箭头图像更改为相反的文件。
最大的问题是,这些控件的宽度和高度需要灵活以允许变化的内容。我在使它起作用方面作了微弱的尝试,但是我知道我在这里缺少很多因素。我的代码甚至没有触摸将箭头按钮与其余按钮一起移动..这也不是为了省力!
有什么帮助吗?谢谢!
HTML:
<div id="main">
<div class="trans" id="trigger">
<img class="arrow_small" src="images/left_small.png" alt="slide out menu" />
</div>
<div id="slider">
<div class="trans" id="overlay"></div>
<div id="content">
<p>this is the content</p>
</div>
</div>
</div>
CSS:
#main {
width:100%;
height:306px;
top:50%;
margin-top:-153px;
position:absolute;
}
#trigger {
width:30px;
height:100%;
float:right;
background-color:#000;
position:relative;
z-index:3;
}
.arrow_small {
position:absolute;
left:50%;
top:50%;
margin-left:-6px;
margin-top:-12px;
}
#overlay {
width:100%;
height:100%;
position:absolute;
}
#content {
width:100%;
height:100%;
position:absolute;
z-index:2;
Javascript:
$(document).ready(function(){
//hide functions
$('#slider').css('display', 'none');
//menu slide out
$('#trigger').click(function (){
var bar = $('#slider');
bar.show(function(){
this.animate({'marginRight':'100%'},1000);
});
});
});
最佳答案
这是您要找的东西吗?在浏览器中尝试一下:
HTML:
<div id="main">
<div id="slider">
<div id="image">
<p>Image would go here</p>
</div>
<div id="content">
<p>content...</p>
</div>
</div>
CSS:
* {
margin: 0;
padding: 0;
}
#slider {
width: 6%;
height: 350px;
top: 33%;
background-color: black;
position: absolute;
right: 0;
}
.arrow_small {
position:absolute;
left:50%;
top:50%;
margin-left:-6px;
margin-top:-12px;
}
#image {
width: 75px;
background-color: black;
position:relative;
color: white;
float: left;
}
#content {
position: relative;
overflow: hidden;
left: 100px;
color: white;
}
js:
$(function() {
$('#image').toggle(function (){
$("#slider").animate({"width":"100%"}, 1000);
}, function() {
$("#slider").animate({"width":"6%"}, 1000);
});
});
我删除了您仅有的图像,因为我没有图像,因此想在本地用文本进行测试。希望这可以帮助!