😎 » JavaScript » Примеры JavaScript » Включить выключить звук в Видео
122 0  

Включить выключить звук в Видео

Этот блок с кнопкой включает и выключает звук в видео:

<div  id="eleID" class="">
	<button onclick="mute(this, 'vid1')">Mute</button>
</div>

Сам код с видео:

<video id="vid1" class=""  autoplay  loop muted poster="video/video.jpg">
		<source src="video/rullan.mp4" type="video/mp4">
</video> 

Виконуваний код:

<!-- Включает и выключает звук в видео --> <script> HTMLElement = typeof(HTMLElement) != 'undefiend' ? HTMLElement : Element; HTMLElement.prototype.addClass = function(string) { if (!(string instanceof Array)) { string = string.split(' '); } for(var i = 0, len = string.length; i < len; ++i) { if (string[i] && !new RegExp('(\s+|^)' + string[i] + '(\s+|$)').test(this.className)) { this.className = this.className.trim() + ' ' + string[i]; } } } HTMLElement.prototype.removeClass = function(string) { if (!(string instanceof Array)) {string = string.split(' ');} for(var i = 0, len = string.length; i < len; ++i) {this.className = this.className.replace(new RegExp('(\s+|^)' + string[i] + '(\s+|$)'), ' ').trim();} } HTMLElement.prototype.toggleClass = function(string) { if (string) { if (new RegExp('(\s+|^)' + string + '(\s+|$)').test(this.className)) { this.className = this.className.replace(new RegExp('(\s+|^)' + string + '(\s+|$)'), ' ').trim(); } else { this.className = this.className.trim() + ' ' + string; } } } HTMLElement.prototype.hasClass = function(string) { return string && new RegExp('(\s+|^)' + string + '(\s+|$)').test(this.className); } document.getElementById('eleID').onclick = function() { this.toggleClass('sound-active'); } </script> <script> function mute(btn,elem){ var video = document.getElementById(elem); if (video.muted){ video.muted = false; btn.innerHTML = "Mute"; } else{ video.muted = true; btn.innerHTML = "Sound"; } } </script>

Залишити свій коментар:

Досвід у веброзробці:

2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2009
2023