依托于bootstracp的jquery滑动开关
2016-11-21 12:23
309 查看
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>jquery做的滑动按钮开关</title> <link rel="stylesheet" type="text/css" href="bootstrap.min.css"/> </head> <style> .switch{ width: 100px; margin: 100px 0px 0 100px; } .btn_fath{ margin-top: 10px; position: relative; border-radius: 20px; <!--添加圆角边框 --> } .btn1{ float: left; } .btn2{ float: right; } .btnSwitch{ height: 40px; width: 50px; border:none; color: #fff; line-height: 40px; font-size: 16px; text-align: center; z-index: 1; } .move{ z-index: 100; width: 40px; border-radius: 20px; height: 40px; position: absolute; cursor: pointer; border: 1px solid #828282; background-color: #f1eff0; box-shadow: 1px 2px 2px 1px #fff inset,0 0 5px 1px #999;<!-- 添加阴影--> } .on .move{ left: 60px; } .on.btn_fath{ background-color: #5281cd; } .off.btn_fath{ background-color: #828282; } </style> <body> <div class="switch"> <div class="btn_fath clearfix on" onclick="toogle(this)"> <div class="move" data-state="on"></div> <div class="btnSwitch btn1">ON</div> <div class="btnSwitch btn2 ">OFF</div> </div> <div class="btn_fath clearfix off" onclick="toogle(this)"> <div class="move" data-state="off"></div> <div class="btnSwitch btn1">ON</div> <div class="btnSwitch btn2 ">OFF</div> </div> </div> <script type="text/javascript" src="../jquery效果/js/jquery.min.js"></script> <script type="text/javascript" src="bootstrap.min.js"></script> <script type="text/javascript"> function toogle(th){ var ele = $(th).children(".move"); if(ele.attr("data-state") == "on"){ ele.animate({left: "0"}, 300, function(){ ele.attr("data-state", "off"); // alert("关!"); }); $(th).removeClass("on").addClass("off"); }else if(ele.attr("data-state") == "off"){ ele.animate({left: '60px'}, 300, function(){ $(this).attr("data-state", "on"); //alert("开!"); }); $(th).removeClass("off").addClass("on"); } } </script> </body> </html>
相关文章推荐
- jQuery 如何实现一个滑动按钮开关
- 利用jquery做的滑动按钮开关
- jQuery滑动开关按钮效果
- JQuery实现滑动开关效果
- 利用jQuery实现滑动开关按钮效果(附demo源码下载)
- jQuery 如何实现一个滑动按钮开关
- JQuery实现滑动开关效果
- jquery 鼠标滑动显示详情应用示例
- 滑动开关-----自定义
- jquerymobile-7 表单基础 radio buttons和checkboxes select menu 搜索框、滑动按钮(Slider)、开关(Flip toggle switch)
- 基于jQuery鼠标滚轮滑动到页面节点部分
- Jquery左右滑动插件之实现超级炫酷动画效果附源码下载
- 『HTML5制作仿JQuery效果』减速&加速滑动的实现
- 基于jQuery和CSS3超酷Material Design风格滑动菜单导航特效
- 基于jQuery和hwSlider实现内容左右滑动切换效果附源码下载(一)
- Jquery-menu-aim流畅的菜单滑动体验
- 一款基于jquery滑动后固定于顶部的导航
- 好用的切换滑动焦点图框架jquery.superslide
- jQuery+slidereveal实现的面板滑动侧边展出效果
- CSS3模拟IOS滑动开关