|
|

楼主 |
发表于 2024-6-21 19:51
|
显示全部楼层
本帖最后由 马黑黑 于 2024-6-21 22:27 编辑
模板代码- <div id="papa"></div>
- <audio id="aud" src="https://music.163.com/song/media/outer/url?id=1892270789" autoplay loop></audio>
- <script type="text/javascript">
- const offsetX = 81, limit = { x: 1400, y: 900};
- const loadImage = (src) => {
- const img = document.createElement('img');
- img.onload = () => {
- let w = Math.min(limit.x, img.naturalWidth), h = Math.min(limit.y, img.naturalHeight);
- adjust(w,h,src);
- };
- img.src = src;
- img.onerror = () => console.log('图片加载失败!');
- };
- const adjust = (width, height, uri) => {
- papa.style.cssText += `
- position: relative;
- width: ${width}px;
- height: ${height}px;
- left: calc(50% - ${offsetX}px);
- transform: translate(-50%);
- background: url(${uri}) center / ${width}px ${height}px;
- z-index: 1;
- `;
- };
- const imgUri = 'https://clubimg.club.vmall.com/data/attachment/forum/202006/03/210541xvw70vguz2bjatza.jpg';
- loadImage(imgUri);
- papa.onclick = () => aud.paused ? aud.play() : aud.pause();
- </script>
复制代码
|
|