處理鍵盤快捷鍵的JavaScript庫:Combokeys
Combokeys是一個在瀏覽器中處理鍵盤快捷鍵的JavaScript庫。
整個庫大約只有 1.9kb ,沒有其它依賴,經測試支持以下瀏覽器:
- Internet Explorer 6+ (test suite works in IE9+)
- Safari
- Firefox
- Chrome </ul>
它已經支持 keypress
, keydown
, 和keyup
事件在特定鍵,組合鍵或按鍵順序。
// single keys combokeys.bind('4', function() { console.log('4'); }); firstCombokeys.bind("?", function() { console.log('show shortcuts!'); }); secondCombokeys.bind('esc', function() { console.log('escape'); }, 'keyup'); // combinations combokeys.bind('command+shift+k', function() { console.log('command shift k'); }); // map multiple combinations to the same callback combokeys.bind(['command+k', 'ctrl+k'], function() { console.log('command k or control k'); // return false to prevent default browser behavior // and stop event from bubbling return false; }); // gmail style sequences Combokeys.bind('g i', function() { console.log('go to inbox'); }); Combokeys.bind('* a', function() { console.log('select all'); }); // konami code! Combokeys.bind('up up down down left right left right b a enter', function() { console.log('konami code'); });
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!