原文鏈接:http://www.exp99.com/f2e/iCheck.html 謝謝小念的博客
iCheck
特色:
1、在不同瀏覽器(包括ie6+)和設備上都有相同的表現 — 包括 桌面和移動設備
2、支持觸摸設備 — iOS、Android、BlackBerry、Windows Phone等系統
4、方便定制 — 用HTML 和 CSS 即可為其設置樣式 (多套皮膚)
5、體積小巧 — gzip壓縮后只有1 kb
6、25 種參數 用來定制復選框(checkbox)和單選按鈕(radio button)
7、8 個回調事件 用來監聽輸入框的狀態
8、7個方法 用來通過編程方式控制輸入框的狀態
9、能夠將輸入框的狀態變化同步回原始輸入框中, 支持所有選擇器

iCheck插件表單美化效果圖
- $('input').iCheck('check'); //將輸入框的狀態設置為checked
- $('input').iCheck('uncheck'); //移除 checked 狀態
- $('input').iCheck('toggle'); //toggle checked state
- $('input').iCheck('disable'); //將輸入框的狀態設置為 disabled
- $('input').iCheck('enable'); //移除 disabled 狀態
- $('input').iCheck('update'); //apply input changes, which were done outside the plugin
- $('input').iCheck('destroy'); //移除iCheck樣式
- //基礎使用方法
- $('input').iCheck({
- labelHover : false,
- cursor : true,
- checkboxClass : 'icheckbox_square-blue',
- radioClass : 'iradio_square-blue',
- increaseArea : '20%'
- });
- {
- handle: '',
- checkboxClass: 'icheckbox',
- radioClass: 'iradio',
- checkedClass: 'checked',
- checkedCheckboxClass: '',
- checkedRadioClass: '',
- uncheckedClass: '',
- uncheckedCheckboxClass: '',
- uncheckedRadioClass: '',
- disabledClass: 'disabled',
- disabledCheckboxClass: '',
- disabledRadioClass: '',
- enabledClass: '',
- enabledCheckboxClass: '',
- enabledRadioClass: '',
- hoverClass: 'hover',
- focusClass: 'focus',
- activeClass: 'active',
- labelHover: true,
- labelHoverClass: 'hover',
- increaseArea: '',
- cursor: false,
- inheritClass: false,
- inheritID: false,
- insert: ''
- }
皮膚
Black — minimal.css //黑色
Red — red.css //紅色
Green — green.css //綠色
Blue — blue.css //藍色
Aero — aero.css //win7中的那種玻璃效果
Grey — grey.css //銀灰色
Orange — orange.css //橙色
Yellow — yellow.css //黃色
Pink — pink.css //粉紅色
Purple — purple.css //紫色
(請自行下載這些皮膚包)
初始化
首先,引入jQuery庫文件
其次,引入jquery.icheck.js插件文件
(如果要引入相關皮膚,則需引入:相關主題顏色.css文件)
事件名稱 | 使用時機 |
---|---|
ifClicked | 用戶點擊了自定義的輸入框或與其相關聯的label |
ifChanged | 輸入框的 checked 或 disabled 狀態改變了 |
ifChecked | 輸入框的狀態變為 checked |
ifUnchecked | checked 狀態被移除 |
ifDisabled | 輸入框狀態變為 disabled |
ifEnabled | disabled 狀態被移除 |
ifCreated | 輸入框被應用了iCheck樣式 |
ifDestroyed | iCheck樣式被移除 |
使用on()方法綁定事件:
- $('input').on('ifChecked', function(event){ //ifCreated 事件應該在插件初始化之前綁定
- alert(event.type + ' callback');
- });
bootstrap iCheck中的radio和checkbox的大小可以調整嗎?
- .icheckbox_square-blue, .iradio_square-blue {
- display: block;
- margin: 0;
- padding: 0;
- width: 22px;
- height: 22px;
- background: url(blue.png) no-repeat;
- border: none;
- cursor: pointer;
- }
如果要調整icheck的radio或checkbox樣式,通過上面的css修改width和height,同時修改blue.png圖片對應的尺寸。