请马上登录,朋友们都在花潮里等着你哦:)
您需要 登录 才可以下载或查看,没有账号?立即注册
x
<style>
#heart { fill: pink; stroke: red; stroke-width: 4; transition: 0.25s; cursor: pointer; }
</style>
<svg id="msvg" width="200" height="200" xmlns="http://www.w3.org/2000/svg" viewBox="-200 -200 400 400">
<path id="heart" d="M0 190 C-200 20,-300 -320,0 -100 C300 -320,200 20,0 190" stroke-dasharray="1227" stroke-dashoffset="1227">
<title id="tit">播放/暂停</title>
</path>
</svg>
<audio id="aud" src="https://music.163.com/song/media/outer/url?id=555121065" autoplay loop></audio>
<script>
const pathlength = heart.getTotalLength(); // 获取路径长度
// 音频播放时 : 进度变更+跳动
aud.ontimeupdate = () => {
heart.setAttribute('stroke-dashoffset', pathlength - pathlength * aud.currentTime / aud.duration);
heart.setAttribute('opacity', Math.random() * 0.5 + 0.5);
};
// 点击心形路径 : 播放/暂停
heart.onclick = () => aud.paused ? aud.play() : aud.pause();
// 提示语
aud.onplaying = aud.onpause = () => tit.textContent = aud.paused ? '点击播放' : '点击暂停';
</script>
|