Skip to content

Instantly share code, notes, and snippets.

@zjutszl
Created June 3, 2019 15:47
Show Gist options
  • Save zjutszl/830d0cba3ffb9206e0e4e78c4d1a3f15 to your computer and use it in GitHub Desktop.
Save zjutszl/830d0cba3ffb9206e0e4e78c4d1a3f15 to your computer and use it in GitHub Desktop.
显示简书图片的脚本
// 节流
function debounce(fn, delay) {
var timer
return function() {
var context = this
var args = arguments
clearTimeout(timer)
timer = setTimeout(function() {
fn.apply(context, args)
}, delay)
}
}
const showTruePic = ()=>{
document.querySelectorAll('.image-view').forEach(node => {
const newNode = node.cloneNode(true) // 克隆container节点
newNode.classList.remove("image-view-maintain"); // 去除cover的样式
const oldImage = node.getElementsByTagName('img')[0]
const newImage = oldImage.cloneNode(true) // 克隆item节点
newImage.src = oldImage.dataset.originalSrc // 设置src
newImage.classList.remove("image-loading"); // 去除蒙层
newNode.appendChild(newImage) // 添加item节点到container节点
node.parentElement.replaceChild(newNode, node) // 更新旧的container节点
}
)
}
// 加载时直接执行一次
showTruePic()
// 每次滚动,都执行一次
window.addEventListener("scroll", debounce(showTruePic, 1000));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment