【问题标题】:How to change color of a part of an image using jquery如何使用jquery更改图像部分的颜色
【发布时间】:2018-11-01 16:51:40
【问题描述】:

我搜索了很多。但是无法做出决定,我是否应该使用带有区域标签的画布 api 或 html 映射来在单击特定颜色时为图像的一部分着色。就像,下面的链接。

Example link

请给我建议,我应该以哪种方式去或尝试制作?

【问题讨论】:

    标签: jquery html html5-canvas


    【解决方案1】:

    你试过了吗?

    HTML Tag Area

    已编辑: 我不是专家,但我不相信只有做某事的方法。我有我的 ptoject 标签区。

    我找到了这个,也许可以帮到你。

    Canvas

    HTML

    <canvas id="canvas" width="400" height="200" class="playable-canvas"></canvas>
    <div class="playable-buttons">
      <input id="edit" type="button" value="Edit" />
      <input id="reset" type="button" value="Reset" />
    </div>
    <textarea id="code" class="playable-code">
    ctx.fillStyle = 'green';
    ctx.fillRect(10, 10, 100, 100);</textarea>
    

    JS

    var canvas = document.getElementById('canvas');
    var ctx = canvas.getContext("2d");
    var textarea = document.getElementById('code');
    var reset = document.getElementById('reset');
    var edit = document.getElementById('edit');
    var code = textarea.value;
    
    function drawCanvas() {
      ctx.clearRect(0, 0, canvas.width, canvas.height);
      eval(textarea.value);
    }
    
    reset.addEventListener('click', function() {
      textarea.value = code;
      drawCanvas();
    });
    
    edit.addEventListener('click', function() {
      textarea.focus();
    })
    
    textarea.addEventListener('input', drawCanvas);
    window.addEventListener('load', drawCanvas);
    

    【讨论】:

    • 我认为,它可以通过区域标签来完成,但在我看到的某个地方,最好使用 canvas api 或 svg。我想知道,对于这种类型的任务,哪种方法最好?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-27
    • 1970-01-01
    • 2018-10-24
    • 1970-01-01
    • 2012-08-12
    相关资源
    最近更新 更多