瞄点平滑跳转

根据id,获取目标元素,通过 scrollIntoView 添加平滑效果

  1. function anchor (el) {
  2. const element = document.getElementById(el.id)
  3. element.scrollIntoView({ behavior: 'smooth' })
  4. }

复制文本

https://zhuanlan.zhihu.com/p/53382478
https://www.jb51.net/article/201421.htm
https://blog.csdn.net/zhenghhgz/article/details/106273496

input | textarea

  1. function copy (text) {
  2. const ipt = document.createElement('input');
  3. document.body.appendChild(ipt);
  4. ipt.setAttribute('value', text);
  5. ipt.select()
  6. console.log(ipt);
  7. try {
  8. // 'document.execCommand' is deprecated
  9. document.execCommand('copy');
  10. } catch (error) {
  11. console.log(error);
  12. } finally {
  13. document.body.removeChild(ipt)
  14. }
  15. }

selectAllChildren

页面居底

https://www.jianshu.com/p/c464576a43e4

  1. handle() {
  2. console.log('到了底部')
  3. window.removeEventListener('scroll', this.handleScroll)
  4. },
  5. handleScroll() {
  6. const ele = document.documentElement
  7. const body = document.body
  8. // 距离顶部距离
  9. const scrollTop = ele.scrollTop || body.scrollTop
  10. // 可视区高度
  11. const windowHeight = ele.clientHeight || body.clientHeight
  12. // 滚动条总高度
  13. const scrollHeight = ele.scrollHeight || body.scrollHeight
  14. if (scrollTop + windowHeight == scrollHeight) {
  15. // window.removeEventListener('scroll', handleScroll) // ?直接写
  16. handle()
  17. console.log('到了底部')
  18. }
  19. },
  20. window.addEventListener('scroll', handleScroll)

input number 上下箭头

  1. input::-webkit-outer-spin-button,
  2. input::-webkit-inner-spin-button {
  3. -webkit-appearance: none;
  4. }
  5. input[type="number"] {
  6. -moz-appearance: textfield;
  7. }