vue中檢測敏感詞,錨點


當發布文章的時候,標題有敏感詞

則檢測有敏感詞的接口成功的時候,寫錨點

eg:

 

_this
.$alert("檢測到標題有敏感詞,請修改后再發布", "提示", {
cancelButtonText: "取消",
confirmButtonText: "確定",
showCancelButton: false,
customClass: "applySuccessBox",
cancelButtonClass: "cancelButtonClass",
confirmButtonClass: "confirmButtonClass",
showClose: false,
center: true,
lockScroll: false
})
.then(() => {
var anchor = _this.$el.querySelector('#myTitle')
document.body.scrollTop = anchor.offsetTop
這里應該再加一句話
document.documentElement.scrollTop = anchor.offsetTop

})
.catch(() => {});
在標題那里加個id=
myTitle
就可以了

 *****************************************************************************************************************

 

上面這么做有bug,360急速模式可以滾動,但是谷歌切沒法滾動,這就尷尬了啊

那是應為

谷歌瀏覽器只認識document.body.scrollTop;

 

注:標准瀏覽器是只認識

document.documentElement.scrollTop的,但chrome雖然我感覺比firefox還標准,但卻不認識這個,在有文檔聲明時,chrome也只認識document.body.scrollTop
因為document.body.scrollTop與document.documentElement.scrollTop兩者有個特點,就是同時只會有一個值生效
經過我實驗谷歌只認識
document.documentElement.scrollTop
其他標准認識
document.body.scrollTop

區別在於
body是DOM對象里的body子節點,即 <body> 標簽; 
documentElement 是整個節點樹的根節點root,即<html> 標簽; 
所以兼容寫法
var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
當你定義一個id作為錨點(能拿到苗點到頂部距離),點擊時要跳到苗點的話就用
vue 中
let anchor = _this.$el.querySelector('#myTitle')

document.documentElement.scrollTop = anchor.offsetTop
document.body.scrollTop = anchor.offsetTop


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM