本文摘自PHP中文网,作者php中世界最好的语言,侵删。
这次给大家带来jQuery怎么实现左右滑动的toggle,jQuery实现左右滑动toggle的注意事项有哪些,下面就是实战案例,一起来看一下。我们知道使用 jQuery 来实现上下移入移除,可以直接使用 slideUp() 和 slideDown() 方法。
slideUp()方法和slideDown()方法只会改变元素的高度。如果一个元素的 display 属性值为 “none”,当调用 slideDown() 方法时,这个元素将由上至下延伸显示。slideUp()方法正好相反,元素将由上到下缩短隐藏。
代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | <!DOCTYPE html>
<html lang= "en" >
<head>
<meta charset= "UTF-8" >
<title>toggle-jquery1.9</title>
<script src= "https://cdn.bootcss.com/jquery/1.9.0/jquery.min.js" ></script>
<style>
p.container {
height: 320px;
border: 1px solid #ccc;
}
p.left {
width: 200px;
height: 300px;
background-color: #36f;
}
</style>
</head>
<body>
<p class = "container" >
<p class = "left" ></p>
</p>
<button id= "toggle" >toggle</button>
<script>
$(document).ready( function (){
$( '#toggle' ).click( function (){
$( '.left' ).slideToggle(300);
});
});
</script>
</body>
</html>
|

那么,要实现左右的滑入滑出呢?
demo 如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | <!DOCTYPE html>
<html lang= "en" >
<head>
<meta charset= "UTF-8" >
<title>toggle-jquery1.9</title>
<script src= "https://cdn.bootcss.com/jquery/1.9.0/jquery.min.js" ></script>
<style>
p.container {
height: 320px;
border: 1px solid #ccc;
}
p.left {
width: 200px;
height: 300px;
background-color: #36f;
}
</style>
</head>
<body>
<p class = "container" >
<p class = "left" ></p>
</p>
<button id= "toggle" >toggle</button>
<script>
$(document).ready( function (){
$( '#toggle' ).click( function (){
$( '.left' ).animate({width: 'toggle' },350);
});
});
</script>
</body>
</html>
|
效果如下:

相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!
推荐阅读:
AjaxUpLoad.js怎样实现文件上传
操作Vue渲染与插件加载的顺序
以上就是jQuery怎么实现左右滑动的toggle的详细内容,更多文章请关注木庄网络博客!
相关阅读 >>
jQuery如何清空input中的内容
如何判断jQuery class是否存在
jQuery读取json乱码怎么办
怎么用jQuery做弹出窗口
详解jQuery中的get方法
详解jQuery中extend()和jQuery.fn.extend()的区别
jQuery中的webix是什么
jQuery如何获取随机数不重复
jQuery如何给不存在的元素添加事件
jQuery怎么获取a标签中href的值
更多相关阅读请进入《jQuery》频道 >>
人民邮电出版社
本书对 Vue.js 3 技术细节的分析非常可靠,对于需要深入理解 Vue.js 3 的用户会有很大的帮助。——尤雨溪,Vue.js作者
转载请注明出处:木庄网络博客 » jQuery怎么实现左右滑动的toggle