Slide to side with jquery on click and toggle

自古美人都是妖i 提交于 2019-12-08 10:42:42

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!