Absolutely! Let's give your Blogger background music a mute/play button so users can control it — and you stay in their good books 😄
✅ HTML + JavaScript Code for Background Music with Mute/Play Button
Paste this into a HTML/JavaScript gadget or directly into your Blogger theme where you'd like the button to appear:
<!-- Background Music Player -->
<audio id="bg-music" autoplay loop>
<source src="YOUR_AUDIO_FILE_URL.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
<!-- Mute/Play Button -->
<button id="music-toggle" style="position:fixed; bottom:20px; right:20px; z-index:9999; padding:10px 15px; font-size:16px;">
🔊 Music On
</button>
<script>
const music = document.getElementById('bg-music');
const toggleBtn = document.getElementById('music-toggle');
// Check if audio is playing
function isPlaying(audio) {
return !audio.paused;
}
toggleBtn.addEventListener('click', () => {
if (isPlaying(music)) {
music.pause();
toggleBtn.textContent = '🔇 Music Off';
} else {
music.play();
toggleBtn.textContent = '🔊 Music On';
}
});
</script>
You can also add
hidden
if you don’t want the player to be visible:
🔧 What to Do:
-
Replace
YOUR_AUDIO_FILE_URL.mp3
with your direct mp3 link. -
The button will appear fixed at the bottom-right of your page.
-
Visitors can toggle the music on/off easily.
💡 Optional Styling Tip:
You can change the button’s look with CSS or replace it with an icon or image for a fancier feel.
Want me to help with a custom-styled button or icon version too?
No comments:
Post a Comment