|
|

楼主 |
发表于 2022-7-17 15:37
|
显示全部楼层
代码:
<style>
#bird {
position: absolute;
width: 73px;
height: 83px;
transition: left 2s, top 2s;
}
</style>
<img id="bird" src="/data/attachment/forum/202207/17/112951jm0vqgv98w8z3h3z.gif" alt="">
<audio id="aud" src="https://music.163.com/song/media/outer/url?id=5268746.mp3" autoplay="autoplay" loop="loop"></audio>
<script>
let lastX = 0;
document.addEventListener('click', (e) => {
e = event || window.event;
let x = e.pageX, y = e.pageY,
w = document.body.clientWidth, h = document.body.clientHeight,
bw = bird.offsetWidth, bh = bird.offsetHeight;
if(x + bw >= w) x = w - bw;
if(y + bh >= h) y = h - bh;
bird.style.transform = x > lastX ? 'rotateY(180deg)' : 'rotateY(0deg)';
console.log(x,lastX,x > lastX);
lastX = x;
bird.style.left = x + 'px';
bird.style.top = y + 'px';
});
</script> |
|