//文本域输入自适应高度
var textarea = document.getElementById('reserve-input');
function makeExpandingArea(el) {
var setStyle = function(el) {
el.style.height = 'auto';
el.style.height = el.scrollHeight + 'px';
}
var delayedResize = function(el) {
window.setTimeout(function() {
setStyle(el)
},
0);
}
if (el.addEventListener) {
el.addEventListener('input', function() {
setStyle(el)
}, false);
setStyle(el)
} else if (el.attachEvent) {
el.attachEvent('onpropertychange', function() {
setStyle(el)
});
setStyle(el)
}
if (window.VBArray && window.addEventListener) { //IE9
el.attachEvent("onkeydown", function() {
var key = window.event.keyCode;
if (key == 8 || key == 46) delayedResize(el);
});
el.attachEvent("oncut", function() {
delayedResize(el);
}); //处理粘贴
}
}
makeExpandingArea(textarea);//方法调用
//解决iOS端input触发焦点的时候,键盘会有遮住输入框的情况
$(document).on('click', '#reserve-input', function() {
var target = this;
setTimeout(function() {
target.scrollIntoView(true)
}, 100)
})
//点击任何区域隐藏元素,其中的e是event事件对象
e.target.tagName.toLowerCase()
网友评论