jQuery和Bootstrap 平滑动画切换控制插件 Bootstrap切换

  • 源码大小:146.1KB
  • 所需积分:1积分
  • 源码编号:19JP-3432
  • 浏览次数:593次
  • 最后更新:2023年06月12日
  • 所属栏目:表单
本站默认解压密码:19jp.com 或 19jp_com

简介

Bootstrap Toggle是一个jQuery插件,它将复选框变成动画和高度可定制的切换控件。

与引导程序2.x、3.x、4.x和5.x兼容。

参见:

  • JavaScript和纯CSS中的10个最佳切换开关

如何使用它:

1.在Html页面中加载jQuery库和Twitter的Bootstrap框架。

  1. <link rel="stylesheet" href="bootstrap.min.css">
  2. <script src="bootstrap.min.js"></script>
  3. <script src="jquery.min.js"></script>

2.在页面中加载jQuery Bootstrap toggle插件的样式表和Javascript

  1. <link href="css/bootstrap-toggle.css" rel="stylesheet">
  2. <script src="js/bootstrap-toggle.js"></script>

3.使用数据切换=“切换”用于自动初始化的属性。

  1. <input type="checkbox" checked data-toggle="toggle">

4.您也可以在Javascript中初始化插件。

  1. $(function() {
  2. $('input[type="checkbox"]').bootstrapToggle();
  3. })

5.在初始化过程中覆盖以下设置。您也可以使用Html5传递它们数据-*嵌入的属性输入标签

  1. // Text of the on toggle
  2. on: 'On',
  3.  
  4. // Text of the off toggle
  5. off: 'Off',
  6.  
  7. // Style of the on toggle. Possible values are:
  8. // default, primary, success, info, warning, danger
  9. onstyle: 'primary',
  10.  
  11. // Style of the off toggle. Possible values are:
  12. // default, primary, success, info, warning, danger
  13. offstyle: 'default',
  14.  
  15. // Sizeof the off toggle. Possible values are:
  16. // default, mini, small, large, normal
  17. size: 'normal',
  18.  
  19. // Custom styles
  20. style: ''
  21.  
  22. // Custom size
  23. width: null,
  24. height: null

6.公开方法。

  1. // Initializes the plugin with options
  2. $('input[type="checkbox"]').bootstrapToggle()
  3.  
  4. // Destroys the toggle
  5. $('input[type="checkbox"]').bootstrapToggle('destroy')
  6.  
  7. // Sets the toggle to 'On' state
  8. $('input[type="checkbox"]').bootstrapToggle('on')
  9.  
  10. // Sets the toggle to 'Off' state
  11. $('input[type="checkbox"]').bootstrapToggle('off')
  12.  
  13. // Toggles the state of the toggle
  14. $('input[type="checkbox"]').bootstrapToggle('toggle')
  15.  
  16. // Enables the toggle
  17. $('input[type="checkbox"]').bootstrapToggle('enable')
  18.  
  19. // Disables the toggle
  20. $('input[type="checkbox"]').bootstrapToggle('disable')

更新日志:

2022-08-10

  • 添加了Bootstrap 5版本。

2020-02-16

  • 添加了Bootstrap 4版本。

预览截图