HTML&JS
in HTML with 0 comment

HTML&JS

in HTML with 0 comment

clientWidth , offsetHeight 等属性详解 参考

获取元素最终CSS属性值

示例:

let end_style = window.getComputedStyle(document.getElementByID('test'))
alert(end_style.marginTop)

通过 targetObj 寻找 className 为 xxx 的 EleObj

let find_ParentTarByClassName = (target, className) => {
            try {
                while (true) {
                    if (!!target.classList && target.classList.contains(className)) {
                        break;
                    } else {
                        target = target.parentNode;
                    }
                }
                return target;

            } catch (error) {

            }
        }

鼠标滚轮横向滚动

            let ScrollEle = document.querySelector('.scroll-task-main')

            function MouseWheel(e) {
                e = e || window.event;
                if (e.stopPropagation) {
                    e.stopPropagation();
                } else {
                    e.cancelBubble = true;
                }

                if (e.preventDefault) {
                    e.preventDefault();
                } else {
                    e.returnValue = false;
                }

                if (e.wheelDelta > 0) {
                    ScrollEle.scrollLeft -= 60
                } else {
                    ScrollEle.scrollLeft += 60
                }

            }
            ScrollEle.onmousewheel = MouseWheel

textarea自动增高并隐藏滚动条

<textarea id="tValue" style="overflow-y:hidden; height:20px;" onpropertychange="this.style.height=this.scrollHeight + 'px'" oninput="this.style.height=this.scrollHeight + 'px'"></textarea>

父容器draggabel为true,子节点不管是否都能移动

scrollIntoView

textarea高度自适应 参考1参考2

input、textarea、div(contenteditable=true)光标定位到最后 参考1


扫描二维码,在手机上阅读!
Comments are closed.