那是我的代码笔: http ://codepen.io/helloworld/pen/pvPzLa
当您按下左/右 V 形按钮滑动时,div 不会第一次向右滑动,而是从右向左滑动。
我知道原因是我最初将可见性属性设置为隐藏/折叠。
当用户单击滑动按钮时,我会从要滑动的 div 中删除可见性属性。
我该如何解决错误的行为?
HTML
<div id="availableOptionsSidebar" style="background-color:pink;" class="col-lg-1">
<div id="availableOptionSidebarContainer" style="text-align:center;display: table;z-index:100000;background-color:orange;">
<span id="availableOptionSidebarContainerOpener" style="cursor:pointer;font-size:2em;display:table-cell;vertical-align:middle;" class="glyphicon glyphicon-chevron-left"></span>
<div style="position:relative;height:100%;">
<div id="availableOptionsContainer" style="position:absolute;height:100%;width:180px;border:black solid 1px;background-color:red;">
<div>
<span style="cursor:pointer;font-size:2em;display:table-cell;vertical-align:middle;" class="glyphicon glyphicon-chevron-left"></span>
<span style="cursor:pointer;font-size:2em;display:table-cell;vertical-align:middle;" class="glyphicon glyphicon-chevron-right"></span>
</div>
<div>
<div class="row">
<div>1</div>
<div>2</div>
<div>3</div>
</div>
<div class="row">
<div>1</div>
<div>2</div>
<div>3</div>
</div>
<div class="row">
<div>1</div>
<div>2</div>
<div>3</div>
</div>
</div>
</div>
</div>
</div>
</div>
JAVASCRIPT
$(function () {
$('#parameterContainer').height(400);
$('#availableOptionSidebarContainer').height(400);
$('#availableOptionsContainer').css('visibility', 'hidden');
$('#availableOptionSidebarContainer').click(function () {
$('#availableOptionsContainer').css('visibility', "");
if ($("#availableOptionSidebarContainerOpener").is(".glyphicon-chevron-left")) { // sidebar is closed
$("#availableOptionSidebarContainerOpener").removeClass("glyphicon-chevron-left");
$("#availableOptionSidebarContainerOpener").addClass("glyphicon-chevron-right");
}
else { // sidebar is openend
$("#availableOptionSidebarContainerOpener").removeClass("glyphicon-chevron-right");
$("#availableOptionSidebarContainerOpener").addClass("glyphicon-chevron-left");
}
// Set the effect type
var effect = 'slide';
// Set the options for the effect type chosen
var options = { direction: 'left' };
// Set the duration (default: 400 milliseconds)
var duration = 500;
$('#availableOptionsContainer').toggle(effect, options, duration);
});
});