创建视频控件

时间:2016-10-05 19:29:39

标签: javascript video controls jslint

window.onload = function () {

    "use strict";
    var video = document.getElementById("video"),
        playButton = document.getElementById("play-pause"),
        muteButton = document.getElementById("mute"),
        fullScreenButton = document.getElementById("full-screen"),
        seekBar = document.getElementById("seek-bar"),
        volumeBar = document.getElementById("volume-bar");

    muteButton.addEventListener("click", function () {
        if (video.muted === false) {

            video.muted = true;


            muteButton.innerHTML = "Unmute";
        } else {

            video.muted = false;


            muteButton.innerHTML = "Mute";
        }
    });

    fullScreenButton.addEventListener("click", function () {
        if (video.requestFullscreen) {
            video.requestFullscreen();
        } else if (video.mozRequestFullScreen) {
            video.mozRequestFullScreen(); // Firefox
        } else if (video.webkitRequestFullscreen) {
            video.webkitRequestFullscreen(); // Chrome and Safari
        }
    });

    seekBar.addEventListener("change", function () {

        var time = video.duration * (seekBar.value / 100);

        video.currentTime = time;
    });

    video.addEventListener("timeupdate", function () {

        var value = (100 / video.duration) * video.currentTime;

        seekBar.value = value;
    });

    seekBar.addEventListener("mousedown", function () {
        video.pause();
    });

    seekBar.addEventListener("mouseup", function () {
        video.play();
    });

    volumeBar.addEventListener("change", function () {
        video.volume = volumeBar.value;
    });

这是我的代码,我从JSLint收到3个错误代码。 1.预期'(结束)'在第1栏,而不是第7栏。 2.预期'}'匹配' {'从第1行开始,而不是看到(结束)'。 3.预期&#39 ;;'而是看到'(结束)'。

任何帮助实现这项工作将不胜感激。

1 个答案:

答案 0 :(得分:0)

/*jslint browser: true*/

window.onload = function () {

    "use strict";
    var video = document.getElementById("video"),
        //playButton = document.getElementById("play-pause"),
        muteButton = document.getElementById("mute"),
        fullScreenButton = document.getElementById("full-screen"),
        seekBar = document.getElementById("seek-bar"),
        volumeBar = document.getElementById("volume-bar");

    muteButton.addEventListener("click", function () {
        if (video.muted === false) {

            video.muted = true;


            muteButton.innerHTML = "Unmute";
        } else {

            video.muted = false;


            muteButton.innerHTML = "Mute";
        }
    });

    fullScreenButton.addEventListener("click", function () {
        if (video.requestFullscreen) {
            video.requestFullscreen();
        } else if (video.mozRequestFullScreen) {
            video.mozRequestFullScreen(); // Firefox
        } else if (video.webkitRequestFullscreen) {
            video.webkitRequestFullscreen(); // Chrome and Safari
        }
    });

    seekBar.addEventListener("change", function () {

        var time = video.duration * (seekBar.value / 100);

        video.currentTime = time;
    });

    video.addEventListener("timeupdate", function () {

        var value = (100 / video.duration) * video.currentTime;

        seekBar.value = value;
    });

    seekBar.addEventListener("mousedown", function () {
        video.pause();
    });

    seekBar.addEventListener("mouseup", function () {
        video.play();
    });

    volumeBar.addEventListener("change", function () {
        video.volume = volumeBar.value;
    });
};

这给了我没有错误。 /*jslint browser: true*/是让jslint知道windowdocument等等。我评论过你未使用的playButton。你在代码的末尾忘记了;