用于画布HTML5的Jquery画笔大小滑块 [英] Jquery Brush Size Slider for Canvas HTML5

查看:59
本文介绍了用于画布HTML5的Jquery画笔大小滑块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在尝试为我的Canvas绘图应用程序创建一个笔刷大小滑块,任何人都可以协助解决此问题吗?我发现的一些方法与运行我的应用程序的Jquery库不兼容.

Hello I'm trying to create a brush size slider for my Canvas drawing app, would anyone be able to assist in how to go about this?? A few of the approaches I have found weren't compatible with my Jquery library that I have running my app.

谢谢:)

推荐答案

简单:

  1. 创建类型为 range 的输入元素:

<输入类型=范围min = 1最大值= 100 id = brushSize>

<input type=range min=1 max=100 id=brushSize>

读取其值并应用于上下文的 lineWidth :

Read its value and apply to lineWidth of the context:

$(#brushSize").on("input",function(e){ctx.lineWidth = $(this).val()});

$("#brushSize").on("input", function(e) {
  var v = $(this).val();            // brush size value, example usage:
  //ctx.lineWidth = v;              // context line-width
  $("#val").html($(this).val());    // textual repr.
  $("#val").width(v).height(v);     // brush size rep.
});

#val {
  display:inline-block;
  border-radius:50%;
  background:#000;
  color:#f00;
  width:50px;
  height:50px;
  text-align:center;
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<input type=range min=1 max=100 id=brushSize> <span id=val>50</span>

这篇关于用于画布HTML5的Jquery画笔大小滑块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆