Mar*_* C. 2 javascript jquery image-manipulation html5-canvas camanjs
如果我使用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>
Run Code Online (Sandbox Code Playgroud)
我创建了一个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();
}
});
});
});
Run Code Online (Sandbox Code Playgroud)
我试图告诉程序它需要使用特定的图像来应用过滤器,但它会不断堆叠过滤器.
如何解决这个问题,以便它不会叠加所有过滤器,而是将图像重置为原始图像,然后应用新过滤器?
小智 12
你能做到的只是以下几点:
更改代码的这一部分(实际上你应该只添加一行):
你的代码:
Caman("#photoCanvas", "images/183411_1871156496150_3955828_n.jpg", function () {
// If such an effect exists, use it:
if( effect in this){
this[effect]();
this.render();
}
});
Run Code Online (Sandbox Code Playgroud)
你如何改变它:
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();
}
});
Run Code Online (Sandbox Code Playgroud)
希望现在它很酷:))
请告诉我:)
最好的迪努兹
| 归档时间: |
|
| 查看次数: |
7080 次 |
| 最近记录: |