问题
So i have a site where i need to have a div slide in from side with a click from a button (slide in from left and slide out on right) - and on reclick it should slide out again... So it needs to be hidden from pageload and only become visible once the button is clicked.
I try to make this, but im new to jquery, so if someone could help me proceed, i would appreciate it.
here is a fiddle of how far i am now.
LINK: http://jsfiddle.net/iBertel/zes8a/21/
Jquery:
$('#btn').click(function() {
$('#div1').slideToggle('slow', function() {
});
});
HTML:
<div id="div1">Div 1</div>
<div><a href="#" id="btn">Click</a></div>
CSS:
#div1 {
width:100px; height:100px; background-color:#F30; color:#FFF; text-align:center; font-size:30px;
}
回答1:
$('#btn').click(function() {
$('#div1').animate({width:'toggle'},350);
});
http://jsfiddle.net/zes8a/39/
来源:https://stackoverflow.com/questions/12600473/slide-to-side-with-jquery-on-click-and-toggle