|
|

楼主 |
发表于 2022-7-18 07:26
|
显示全部楼层
一楼代码:
- <style>
- #papa {
- margin: auto;
- width: 1024px;
- height: 640px;
- background: linear-gradient(180deg, #0C003C 0%, #BFFFAF 100%), linear-gradient(165deg, #480045 25%, #E9EAAF 100%), linear-gradient(145deg, #480045 25%, #E9EAAF 100%), linear-gradient(300deg, rgba(233, 223, 255, 0) 0%, #AF89FF 100%), linear-gradient(90deg, #45EBA5 0%, #45EBA5 30%, #21ABA5 30%, #21ABA5 60%, #1D566E 60%, #1D566E 70%, #163A5F 70%, #163A5F 100%);
- background-blend-mode: overlay, overlay, overlay, multiply, normal;
- box-shadow: 4px 4px 28px #000;
- position: relative;
- }
- #bird {
- position: absolute;
- width: 73px;
- height: 83px;
- left: 50%;
- top: 500px;
- transition: left 2s, top 2s;
- }
- </style>
- <div id="papa">
- <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>
- </div>
- <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;
- x = x - offset(papa, 'left');
- y = y - offset(papa, 'top');
- if(x + bw >= w) x = w - bw;
- if(y + bh >= h) y = h - bh;
- bird.style.transform = x > lastX ? 'rotateY(180deg)' : 'rotateY(0deg)';
- lastX = x;
- bird.style.left = x + 'px';
- bird.style.top = y + 'px';
- });
- function offset(obj,direction){//偏移总量
- let offsetDir = "offset" + direction[0].toUpperCase()+direction.substring(1);
- let realNum = obj[offsetDir];
- let positionParent = obj.offsetParent;
- while(positionParent != null){
- realNum += positionParent[offsetDir];
- positionParent = positionParent.offsetParent;
- }
- return realNum;
- }
- </script>
复制代码
|
|