如何修改H5中的audio样式

HTML

<div class="btn-audio clear">
            <img src="image/audioBg.jpg" alt="" class="lf" style="width: 5.2rem;">
            <div class="lf">
                <p style="font-size: 1.2rem; color: #333;margin: 1rem 0 0.3rem 1.2rem;">我要吃肉肉</p>
                <p style="font-size: 1rem; color: #888; margin: 0 0 0 1.2rem">何曼婷 - 我要吃肉肉</p>
            </div>
            <img src="image/musicBg.png" alt="" style="width: 1rem;position: absolute;bottom: 0.5rem;right: 0.5rem;">
            <div class="mp3Box">
                <audio id="mp3Btn">
                    <source src="林玉涵,程辰%20-%20我要吃肉肉(Cover%20何曼婷).mp3" type="audio/mpeg" />
                </audio>
            </div>
        </div>

CSS

.btn-audio{
            width: 100%;
            height: 5.2rem;
            border: 1px solid #ebebeb;
            background-color: #fdfdfd;
            margin-bottom: 1rem;
            margin-top: 1rem;
            position: relative;
        }
        .mp3Box{
            width: 2.8rem;
            height: 2.8rem;
            position: absolute;
            top: 1.2rem;
            left: 1.2rem;
            background:url("image/close.png") no-repeat center bottom;
            background-size:cover;
            z-index: 100;
        }

JS

<script>
    $(function(){
        //播放完毕
        $('#mp3Btn').on('ended', function() {
            console.log("音频已播放完成");
            $('.mp3Box').css({'background':'url(image/close.png) no-repeat center bottom','background-size':'cover'});
        });
        //播放器控制
        var audio = document.getElementById('mp3Btn');
        audio.volume = .3;
        $('.mp3Box').click(function() {
            event.stopPropagation();//防止冒泡
            if(audio.paused){ //如果当前是暂停状态
                $('.mp3Box').css({'background':'url(image/open.png) no-repeat center bottom','background-size':'cover'});
                audio.play(); //播放
            }else{//当前是播放状态
                $('.mp3Box').css({'background':'url(image/close.png) no-repeat center bottom','background-size':'cover'});
                audio.pause(); //暂停
            }
        });
    })
</script>

修改前:

修改后:

  • 5
    点赞
  • 35
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
如果你想在HTML5设置被替换后的文字样式,可以使用CSS来实现。被替换元素是指像`<img>`、`<video>`、`<audio>`等标签,它们会被其内容所替代(例如图片、视频、音频),并且可以通过CSS来控制其样式。 要设置被替换元素的样式,你可以使用以下CSS属性: 1. `width`和`height`:用于设置元素的宽度和高度。 2. `object-fit`:用于指定元素在容器的布局方式,例如`object-fit: cover`表示将元素等比例缩放并填满容器。 3. `object-position`:用于指定元素在容器的位置,例如`object-position: center center`表示将元素居显示。 4. `display`:用于设置元素的显示方式,例如`display: inline-block`表示以内联块级元素显示。 以下是一个示例,展示如何设置被替换元素(例如`<img>`标签)的样式: ```html <style> .replaced-element { width: 300px; height: 200px; object-fit: cover; object-position: center center; display: inline-block; } </style> <img src="path/to/your/image.jpg" class="replaced-element" alt="Description of the image"> ``` 在这个示例,我们使用了一个带有`.replaced-element`类的CSS样式规则来设置被替换元素的样式。然后,我们在`<img>`标签应用了这个类,并指定了图片的路径和替代文本(使用`alt`属性)。 你可以根据需要调整这些CSS属性的值,以满足你的样式要求。同时,你也可以为其他类型的被替换元素(如`<video>`和`<audio>`)应用类似的CSS样式。 希望这可以帮到你!如果你还有其他问题,请随时提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值