js常用API
(1) getAttribute? 用戶寫啥是啥,#后面的值,獲取用戶在上面寫的原文,不是瀏覽器加http協議的東西;
<a?href="#siteAbout">關于</a>
var href = a.getAttribute('href')? ? ? ? ? ? ? ? ? ? ? // href=siteAbout
(1.1) a.href? //帶http協議的,被瀏覽器處理過的
(2) x.preventDefault()? ? //阻止x的默認行為屬性
(3)?querySelector? ? ?//找標簽
document.querySelector('a[href="#'?+?id?+?'"]')
?document.querySelector(href)
(4) querySelectorAll? ? //找所有標簽,返回選擇器所有元素
document.querySelectorAll('[data-x]')
document.querySelectorAll('nav.menu?>ul?>li?>a')
document.querySelectorAll('nav.menu?>ul?>li')
(5) debugger? ? ? //斷點
(6)?Element.getBoundingClientRect()方法返回元素的大小及其相對于視口的位置。
(7) x.offsetTop //返回距離頁面頂部的像素數
(8) window.scrollY // 獲窗口滾動高度
(9) window.onscroll? //滑動窗口時觸發某函數
window.onscroll?=?function?(x)?{
????if?(window.scrollY?>?0)?{
????????topNavBar.classList.add('sticky')
????}?else?{
????????topNavBar.classList.remove('sticky')
? ?}}
(10) setTimeout? //定時器,該定時器在定時器到期后執行一個函數或指定的一段代碼。
setTimeout(function?()?{
????siteWelcome.classList.remove('active')
},?1000);? ? //在1秒后觸發函數
(11) onmouseenter? //當鼠標進入某元素會觸發一個函數;元素綁定了監聽事件后,當一個指針設備(通常是鼠標)移動到這個元素上時mouseenter事件將會被觸發
(12) onmouseleave?當鼠標離開某元素會觸發一個函數
(13)?
?
?
?
?
?
?
總結
- 上一篇: Mysql 外键创建失败原因
- 下一篇: Unity资源管理--AssetBund