简体   繁体   English

如何使用javascript调整图标大小

[英]How to resize icon by using javascript

My cursor that is displayed on canvas is a base64 encoded icon.我在画布上显示的光标是一个base64编码的图标。 So, my assumption is I can not use the <img> tag for it, however, I want to scale this icon.所以,我的假设是我不能使用<img>标签,但是,我想缩放这个图标。 Is there any way doing it?有什么办法吗?

My HTML piece我的 HTML 片段

<canvas style="cursor: url("data:image/x-icon;base64,.....") 0 0, default;"></canvas>

You can size canvas elements the same way as every other kind of element, though you should bear in mind that CSS scaling will not affect the coordinates of the canvas.您可以使用与其他任何类型元素相同的方式调整canvas元素的大小,但您应该记住,CSS 缩放不会影响画布的坐标。 It's generally better practice to use the width and height attributes of the element rather than the style properties.使用元素的widthheight属性而不是样式属性通常是更好的做法。

I'm also not really sure why you think you can't use base64-encoded strings as a src for <img> elements -- this is definitely possible, and I believe is performed in an identical fashion as canvases.我也不太确定为什么您认为不能使用 base64 编码的字符串作为<img>元素的 src —— 这绝对是可能的,我相信它以与画布相同的方式执行。

I could be wrong as far as what you're trying to do, though -- there are some strange errors in your example, like a cursor attribute, and the attribute being defined with a colon instead of an equals, and there being a closing quote for the attribute but no opening quote.不过,就您尝试执行的操作而言,我可能是错误的——您的示例中有一些奇怪的错误,例如cursor属性,并且该属性用冒号而不是等号定义,并且有一个结束属性的引用,但没有开头引用。 I'm also really not sure 0, 0, default section of the attribute is supposed to represent.我也真的不确定0, 0, default属性的0, 0, default部分应该代表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM