如果我用camanJS在我的图像上应用滤镜,一切都很好,但当我单击第二个滤镜时,它需要返回到原始图像并将其应用到该图像上,但目前它将第二个滤镜放在仍然具有第一个滤镜的图像上。
这是我的html部分:
<table>
<tr>
<td><div id="photo"><canvas id="photoCanvas" width="500" height="500">Uw browser ondersteund geen canvas</canvas></div></td>
<td><div id="filterContainer">
<h4>Please select your photo effect.</h4>
<ul id="filters">
<li> <a href="#" id="normal">Normal</a> </li>
<li> <a href="#" id="vintage">Vintage</a> </li>
<li> <a href="#" id="lomo">Lomo</a> </li>
<li> <a href="#" id="clarity">Clarity</a> </li>
<li> <a href="#" id="sinCity">Sin City</a> </li>
<li> <a href="#" id="sunrise">Sunrise</a> </li>
<li> <a href="#" id="pinhole">Pinhole</a> </li>
</ul>
</div></td>
</tr>
</table>我创建了一个id为photoCanvas的画布,这是用来显示图像的,我有一个带有不同过滤器的列表,如果点击它,就会触发下面的javascript部分:
$(function() {
Caman("#photoCanvas", "./images/183411_1871156496150_3955828_n.jpg", function () {
this.render();
});
var filters = $('#filters li a');
// originalCanvas = $('#canvas'),
// photo = $('#photo');
filters.click(function(e){
e.preventDefault();
var f = $(this);
if(f.is('.active')){
// Apply filters only once
return false;
}
filters.removeClass('active');
f.addClass('active');
// Listen for clicks on the filters
var effect = $.trim(f[0].id);
Caman("#photoCanvas", "images/183411_1871156496150_3955828_n.jpg", function () {
// If such an effect exists, use it:
if( effect in this){
this[effect]();
this.render();
}
});
});
});我试图告诉程序它需要使用特定的图像来应用滤镜,但它一直在堆叠滤镜。
如何修复此问题,使其不会堆叠所有滤镜,而是将图像重置为原始图像,然后应用新滤镜?
发布于 2013-06-12 06:05:41
你能做的简单如下:
更改代码的这一部分(实际上您只需添加一行):
你的代码:
Caman("#photoCanvas", "images/183411_1871156496150_3955828_n.jpg", function () {
// If such an effect exists, use it:
if( effect in this){
this[effect]();
this.render();
}
});您需要如何更改IT:
Caman("#photoCanvas", "images/183411_1871156496150_3955828_n.jpg", function () {
// If such an effect exists, use it:
if( effect in this){
//NOTE THIS IS THE LINE THAT I ADD FOR YOU:
this.revert();
this[effect]();
this.render();
}
});希望现在它工作起来很酷:)
请让我知道:)
最佳Dinuz
https://stackoverflow.com/questions/17040283
复制相似问题