2014-09-02 148 views

回答

1

​​

HTML

<div style="text-align:center"> 
    <video id="playvideo" width="450" controls="controls" > 
    <source src="http://corrupt-system.de/assets/media/sintel/sintel-trailer.m4v" type="video/mp4" />   
    </video> 
    <button class="close">Hide</button> 
</div> 

CSS

video + button.close { 
    font-size: 10px; 
    display: block; 
} 
video.hide { 
    display: none; 
} 

JS

var hideStr = 'Hide', showStr = 'Show', hideClass = 'hide'; 
var buttons = document.querySelectorAll('video + button.close'); 
for(var b = 0; b < buttons.length; b++){ 
    var button = buttons[b]; 
    button.addEventListener('click', function(){ 
    var video = this.parentNode.childNodes[1]; 
    video.muted = !video.muted; 
    video.classList.toggle (hideClass); 
    if(this.textContent == hideStr) this.textContent = showStr; 
    else this.textContent = hideStr; 
    }); 
} 

UPDATE

JQUERY SOLUTION

HTML

<script src="//code.jquery.com/jquery-git1.js"></script> 

JQUERY

var hideStr = 'Hide', showStr = 'Show', hideClass = 'hide'; 
$('video + button.close').click(function(){ 
    var button = $(this); 
    var video = button.parent().find('video'); 
    video.prop('muted', !video.prop('muted')); 
    video.toggleClass(hideClass); 
    if(button.text() == hideStr) button.text(showStr); 
    else button.text(hideStr); 
}); 
+0

我需要X标志位于右上角的媒体播放器 – user3811714 2014-09-02 13:00:30

+0

然后使用CSS移动它。 – patricksweeney 2014-09-02 13:02:15

+0

我该怎么做 – user3811714 2014-09-02 13:03:55

相关问题