leiroc / wipe

Wipe是一款基于HTML5 canvas的移动端,涂抹,自动播放涂抹轨迹,刮刮乐的插件。(The movement of the wiper is a based on HTML 5 canvas, daub, automatic playback daub trajectory, scratch music plug-in.)
https://animpen.com/
Other
68 stars 24 forks source link

页面滚动到非顶部时,刮刮乐失效的问题,解决方案如下 #9

Open Marszed opened 7 years ago

Marszed commented 7 years ago

winTcanvasXY: function (canvas, x, y) { var cC = canvas.getBoundingClientRect();

    // author Marszed https://github.com/Marszed
    // 解决页面滚动,刮刮乐失效的问题
    // FIX chrome对document.documentElement.scrollHeight&document.documentElement.scrollTop是不能识别的,而firefox和IE11不能识别document.body.scrollHeight&document.body.scrollTop
    // 需要减去滚动距离
    var scrollTop = document.body.scrollTop==0?document.documentElement.scrollTop:document.body.scrollTop;

    return {
        x: x - cC.left,
        y: y - cC.top - scrollTop
    }
}