【发布时间】:2016-02-09 11:05:21
【问题描述】:
我有一个 JavaScript 应用程序,可以将过滤器应用于实时视频。
我想知道如何在用户点击过滤器按钮后显示当前过滤器正在使用的 inner.HTML。
我想在此处显示当前滤镜(棕褐色、灰度等)
<p id="filterName"></p>
这是我更改过滤器的代码,我觉得我必须将显示过滤器的代码行放在最后作为过滤器按钮功能的一部分。
// CSS filters
//this array will cycle through the filter effects
var index = 0; //the array starts at 0
var filters = ['grayscale', 'sepia', 'saturate', 'hue', 'invert', 'no-filter'];
// this applies the filter to the video feed, takes the class of the video feed
var changeFilter = function () {
var el = document.getElementById('video');
el.className = 'videoClass';
//this will cycle through the filters, once it hits the final filter it will reset
var effect = filters[index++ % filters.length]
if (effect) {
el.classList.add(effect);
console.log(el.classList);
}
}
//when the user presses the filter button it will apply the first filter in the array
document.getElementById('filterButton').addEventListener('click', changeFilter);
感谢您的宝贵时间。
【问题讨论】:
-
我有第二个问题,我添加了另一个名为 no-filter 的过滤器(它添加了 clear)。我怎么能有在开始显示。截至目前,它仅在我循环通过其他过滤器后显示。
标签: javascript arrays innerhtml imagefilter