高亮提示、聚焦控件并滚动到浏览器中干好可以查看到该控件的位置
生活随笔
收集整理的這篇文章主要介紹了
高亮提示、聚焦控件并滚动到浏览器中干好可以查看到该控件的位置
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
<style>/*高亮提示________________________*/[sg-high-light] { animation: sg-high-light 1s ease 3;}@keyframes sg-high-light {0% {background: rgba(3, 156, 253, 0);}50% {background: rgba(3, 156, 253, 0.2);}100% {background: rgba(3, 156, 253, 0);}}
</style>
<script>/**聚焦焦點*/var focusDOM = {__hl(s) {s.setAttribute("sg-high-light", true);setTimeout(function () {s.removeAttribute("sg-high-light");}, 3000);},to(s, is) {typeof s == "string" && (s = document.querySelector(s));is ? (typeof is == "string" && (is = document.querySelector(is))) : (is = s);is.focus();["input", "textarea"].includes(is.tagName.toLowerCase()) && is.select();s.scrollIntoView({behavior: "smooth", block: "nearest", inline: "nearest"});//緩慢滾動is.scrollIntoView({behavior: "smooth", block: "nearest", inline: "nearest"});//緩慢滾動this.__hl(s);}};
</script>
總結
以上是生活随笔為你收集整理的高亮提示、聚焦控件并滚动到浏览器中干好可以查看到该控件的位置的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: JavaScript原生代码处理JSON
- 下一篇: 使用SCSS高亮显示控件、聚焦位置