失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > jQuery 如何实现一个滑动按钮的开关

jQuery 如何实现一个滑动按钮的开关

时间:2022-02-12 23:16:43

相关推荐

jQuery 如何实现一个滑动按钮的开关

web前端|js教程

jquery,滑动开关按钮,jquery,滑动开关,jquery,滑动按钮

web前端-js教程

本文给大家分享一段jquery代码实现滑动按钮开关的效果,代码简单易懂,非常不错,具有一定的参考借鉴价值,需要的的朋友参考下

himall 2.5源码下载,vscode注释怎么变绿色,ubuntu外部目录,tomcat怎么连接plc,pyter爬虫案例,php时间的加减法,seo综合查询在哪里运营,学历培训学校网站源码,模板制冷机lzw

滑动开关按钮大家在各大网站都能见到,下面给大家分享一篇基于jquery实现的一个滑动按钮开关效果,感兴趣的朋友可以参考下实现代码。

android仿京东源码下载,ubuntu下载rar,tomcat查找端口号,神箭手爬虫新浪,php网站添加验证码,seo具体是做什么的营销lzw

先给大家展示下效果图:

eoe客户端源码,vscode总是卡死,ubuntu 光盘镜像u盘,tomcat自带线程,sqlite实现右连接,shopnc微信支付插件,前端ui框架怎么用用,庆云的爬虫店,php变量的类型,台湾黄怡嘉seo,php二手房网站源码,后台管理网页模板下载,oa查询页面模板,ccms登录页面,cms后台管理系统模板下载,dz7.2程序下载lzw

代码:

jquery做的滑动按钮开关.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; }

ON

OFF

ON

OFF

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"); } }

需要注意的是:

1、这边滑动使用的速度是300ms,好像是匀速,没有线性的快慢那种;试着找下能不能像CSS3中ease那种线性运动的。

2、animate方法中的回调函数,即运动结束后调用的function。

如果觉得《jQuery 如何实现一个滑动按钮的开关》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。