【发布时间】:2014-09-02 12:32:16
【问题描述】:
使用 bootstrap 3 CSS、font awesome CSS 和最新的 jQuery JS 文件。
当单击按钮时,我正在使用 javascript 在另一个内容 div 的顶部隐藏/显示一个内容 div。
HTML
<div class="col-sm-4">
<div class="HScontainer">
<div class="HSouter">
<p>BOTTOM CONTENT</p>
<div class="HSbox">
<p>TOP CONTENT</p>
</div>
</div>
<a href="#" class="HSshowit btn btn-primary" role="button">Show More <i class="fa fa-caret-square-o-up"></i></a>
</div>
</div>
<div class="col-sm-4">
<div class="HScontainer">
<div class="HSouter">
<p>BOTTOM CONTENT</p>
<div class="HSbox">
<p>TOP CONTENT</p>
</div>
</div>
<a href="#" class="HSshowit btn btn-primary" role="button">Show More <i class="fa fa-caret-square-o-up"></i></a>
</div>
</div>
<div class="col-sm-4">
<div class="HScontainer">
<div class="HSouter">
<p>BOTTOM CONTENT</p>
<div class="HSbox">
<p>TOP CONTENT</p>
</div>
</div>
<a href="#" class="HSshowit btn btn-primary" role="button">Show More <i class="fa fa-caret-square-o-up"></i></a>
</div>
</div>
</div></div></div>
CSS
.HScontainer {
overflow:hidden;
}
.HSouter {
position:relative;
width: 300px;
height: 200px;
background: #FBCF3C;
border: 1px solid black;
overflow:hidden;
}
.HSbox {
position:absolute;
bottom:0;
left:0;
width: 300px;
height: 200px;
margin-bottom: -200px;
-webkit-transition: all 0.8s ease;
-moz-transition: all 0.8s ease;
-o-transition: all: 0.8s ease;
transitions: all 0.8s ease;
background: #19A4DA;
}
.HSbox p {
margin: 0;
padding: 5px 0 5px 0;
}
.HSshow {
margin: 0;
}
.HSshowit { width:300px; }
JS
$(function(){
$('.HSshowit').click(function(e) {
$(this).prev('.HSouter').children('.HSbox').toggleClass('HSshow');
});
});
我想改变按钮上的文字
Show More <i class="fa fa-caret-square-o-up"></i>
到
Show Less <i class="fa fa-caret-square-o-down"></i>
这是一个例子……
【问题讨论】:
标签: javascript jquery html css twitter-bootstrap