首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使按钮进入其初始状态

使按钮进入其初始状态
EN

Stack Overflow用户
提问于 2016-01-02 18:17:35
回答 1查看 72关注 0票数 1

现在,我已经开始在我的网站中设置视频控件的样式了,我遇到了一个小问题。

视频部分包含视频列表和视频播放器.每当单击列表中的li元素时,视频播放器的源更改为单击视频的源。在视频播放器的顶部有一个播放按钮,从播放到暂停有一个过渡。

我遇到的问题是,每当视频源改变时,按钮就不会回到播放状态。

HTML代码(index.php):

代码语言:javascript
复制
<div class="control play">
    <span class="left"></span><span class="right"></span>
</div>

这是按钮(Less.less)的较少的样式:

代码语言:javascript
复制
.control {
    @color: #ffb160;
    @highlight: darken(@color, 10%);
    @duration: 0.4s;
    @sin:  0.866;
    @size: 30px;
    border: @size*0.1 solid @color;
    border-radius: 50%;
    margin: 20px;
    padding: @size*0.25;
    width: @size;
    height: @size;
    font-size: 0;
    white-space: nowrap;
    text-align: center;
    cursor: pointer;

    &, .left, .right, &:before {
        display: inline-block;
        vertical-align: middle;
        transition: border @duration, width @duration, height @duration, margin @duration;
        transition-tiomig-function: cubic-bezier(1, 0, 0, 1);
    }

    &:before {
        content: "";
        height: @size;
    }

    &.pause {
        .left, .right {
            margin: 0;
            border-left: @size*0.33 solid @color;
            border-top: 0 solid transparent;
            border-bottom: 0 solid transparent;
            height: @size*@sin;
        }
        .left {
            border-right: @size*0.2 solid transparent;
        }
    }

    &.play {
        @border: @size/4;
        .left {
            margin-left: @size/6;
            border-left: @size*@sin/2 solid @color;
            border-top: @border solid transparent;
            border-bottom: @border solid transparent;
            border-right: 0px solid transparent;
            height: @size - 2*@border;
        }
        .right {
            margin: 0;
            border-left: @size*@sin/2 solid @color;
            border-top: @border solid transparent;
            border-bottom: @border solid transparent;
            height: 0px;
         }
    }

    &:hover {
        border-color: @highlight;
        .left, .right {
            border-left-color: @highlight;
        }
    }
}

这是从播放到暂停(JQuery.js)的过渡:

代码语言:javascript
复制
$(".control").on('mousedown', function() {
    if (video.paused == true) {
        $(this).toggleClass('pause play');
        video.play();
    } else {
        $(this).toggleClass('play pause');
        video.pause();
    }
});

这是通过单击list (JQuery.js)中的li元素触发的事件:

代码语言:javascript
复制
$('.video-element').click(function(){
    var videosource = $(this).find("div.source").html();
    var imgsource = $(this).find(".video-thumbnails").attr("src");

    $(".control").toggleClass('play');
    document.getElementById('video-player').setAttribute('poster',imgsource);
    document.getElementById('mp4').setAttribute('src','videos/'+videosource + ".mp4");
    document.getElementById('ogv').setAttribute('src','videos/'+videosource + ".ogv");
    document.getElementById('webm').setAttribute('src','videos/'+videosource + ".webm");
    $("#video-player").load();
});

到目前为止,我尝试的是将$(".control").toggleClass('play');添加到代码中,因为每次单击新视频时,按钮都会更改为暂停或播放,因此视频的更改无法工作。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-01-02 20:40:41

当您更改视频源时,是否也可以更改播放/暂停按钮的类?也就是说,在您的“单击”函数中,包括

  1. 更改视频源的代码(已完成)。
  2. 将按钮类更改为“play”的代码(使用$(elem).setClass("play")或类似的方法)。
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34569137

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档