我想在点击时隐藏/显示一个 div。当我希望它隐藏时,我希望 div 向左隐藏。我有这个。但是 div 向上隐藏。小提琴
$(document).ready( function() {
$('#showmenu').click( function() {
var hidden = $('.sidebarmenu').data('hidden');
$('#showmenu').text(hidden ? 'Show Menu' : 'Hide Menu');
if ( hidden ) {
$('.sidebarmenu').css({
position: 'absolute',
left: -200000
});
} else {
$('.sidebarmenu').css({
position: '',
left: 0
});
}
$('.sidebarmenu,.image').data("hidden", !hidden);
});
});
这是我的 HTML
<button id="showmenu" type="button">Show menu</button>
<div class="sidebarmenu" style="position: absolute; left: -200000px">
This should go left
</div>