Project1
标题:
(伪)文本框 (我也不知道是什么)反正是文本框
[打印本页]
作者:
寒椿相逢
时间:
前天 16:31
标题:
(伪)文本框 (我也不知道是什么)反正是文本框
function TextInput() { throw new Error("static class"); }
TextInput.text = document.createElement('textarea');
TextInput.isComposing=false
TextInput.event=null
TextInput.install = function() {
TextInput.text.style.position = 'absolute';
TextInput.text.style.opacity = 0;
TextInput.text.disabled = true;
document.body.appendChild(TextInput.text);
TextInput.text.addEventListener('compositionstart', this.onCompositionStart.bind(this));
TextInput.text.addEventListener('compositionend', this.onCompositionEnd.bind(this));
TextInput.text.addEventListener('input', this.changed.bind(this));
}
TextInput.onCompositionStart = function(event) {
this.isComposing = true;
}
TextInput.onCompositionEnd = function(event) {
this.isComposing = false;
if(event.data){
TextInput.event(event.data)
event.target.value=""
}
}
TextInput.changed = function(event) {
if (this.isComposing) {
return;
}
if(event.data){
TextInput.event(event.target.value)
event.target.value=""
}
}
TextInput.location=function (x,y,event){
TextInput.text.style.left = `${x}px`;
TextInput.text.style.top = `${y}px`;
TextInput.text.disabled = false;
TextInput.isInput=false
TextInput.cont=""
TextInput.event=event
TextInput.text.focus();
}
TextInput.disabled=function (){
TextInput.text.style.left = `0px`;
TextInput.text.style.top = `0px`;
TextInput.text.disabled = true;
TextInput.isInput=false
TextInput.cont=""
TextInput.event=null
}
TextInput.install()
TextInput.location(100,100,function (a){console.log(a)})
为了配合canvas层的组件,用奇怪的方法得到textarea中的输入。
反正每次要.location到光标位置,每次输入后在去组件里处理好。
欢迎光临 Project1 (https://rpg.blue/)
Powered by Discuz! X3.1