// 代ç åä¸é®å¤å¶ $(function () { var $copyIcon = $('') var $notice = $('
') $('.code-area').prepend($copyIcon) $('.code-area').prepend($notice) // âå¤å¶æåâååºç° function copy(text, ctx) { if (document.queryCommandSupported && document.queryCommandSupported('copy')) { try { document.execCommand('copy') // Security exception may be thrown by some browsers. $(ctx).prev('.codecopy_notice') .text("å¤å¶æå") .animate({ opacity: 1, top: 30 }, 450, function () { setTimeout(function () { $(ctx).prev('.codecopy_notice').animate({ opacity: 0, top: 0 }, 650) }, 400) }) } catch (ex) { $(ctx).prev('.codecopy_notice') .text("å¤å¶å¤±è´¥") .animate({ opacity: 1, top: 30 }, 650, function () { setTimeout(function () { $(ctx).prev('.codecopy_notice').animate({ opacity: 0, top: 0 }, 650) }, 400) }) return false } } else { $(ctx).prev('.codecopy_notice').text("æµè§å¨ä¸æ¯æå¤å¶") } } // å¤å¶ $('.code-area .fa-copy').on('click', function () { var selection = window.getSelection() var range = document.createRange() range.selectNodeContents($(this).siblings('pre').find('code')[0]) selection.removeAllRanges() selection.addRange(range) var text = selection.toString() copy(text, this) selection.removeAllRanges() }) });