Skip to content

Instantly share code, notes, and snippets.

@CatzillaOrz
Created October 29, 2017 08:25
Show Gist options
  • Save CatzillaOrz/afd7987b3e43f77bd66154756e873b91 to your computer and use it in GitHub Desktop.
Save CatzillaOrz/afd7987b3e43f77bd66154756e873b91 to your computer and use it in GitHub Desktop.
输入延迟触发实现-input_delay
//创建一个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