Created
October 29, 2017 08:25
-
-
Save CatzillaOrz/afd7987b3e43f77bd66154756e873b91 to your computer and use it in GitHub Desktop.
输入延迟触发实现-input_delay
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//创建一个Textarea并监听键盘onkeyup | |
var iframe = document.createElement('iframe'); | |
var re = frame.document.createElement('textarea'); | |
re.id = 'remarkText'; | |
re.style.position='fixed'; | |
re.style.right='0'; | |
re.style.width='99.7%'; | |
re.style.backgroundColor='ghostwhite'; | |
re.style.bottom='22px'; | |
re.style.opacity='.5'; | |
re.style.maxHeight='10%'; | |
re.style.height='10%'; | |
re.style.zIndex = '10'; | |
re.style.visibility='hidden'; | |
re.style.resize = 'none'; | |
re.onkeyup = function() { | |
var value = frame.document.getElementById('remarkText').value; | |
CurrentRemarkText = value; | |
delay(function(){ | |
saveRemark(value); | |
}, 1000 ); | |
} | |
frame.document.getElementById('ChromelessStatusBar.RightDock').appendChild(re); | |
initEnvironment(); | |
} | |
//delay最佳解决方案 | |
var delay = (function(){ | |
var timer = 0; | |
return function(callback, ms){ | |
clearTimeout (timer); | |
timer = setTimeout(callback, ms); | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment