vue.js - 有没有办法在fabricjs onclick中增加和减少字体大小
问题描述
这些是我的步骤:
- 添加虚拟文本
- 单击按钮时增加/减小字体大小
我正在使用 Vue、Javascript 和 jQuery。现在我得到了正确的字体大小,但只有当我添加新文本时。但它应该是动态的。
谢谢帮助
<input type='button' value='-' class='qtyminus' field='quantity' />
<input type='text' name='quantity' value='0' class='qty' />
<input type='button' value='+' class='qtyplus' field='quantity' />
var currentVal = 12;
$('.qtyplus').click(function(e){
e.preventDefault();
currentVal = parseInt($('input[name=quantity]').val());
if (!isNaN(currentVal)) {
$('input[name=quantity]').val(currentVal + 1);
} else {
$('input[name=quantity]').val(0);
}
});
$(".qtyminus").click(function(e) {
e.preventDefault();
currentVal = parseInt($('input[name=quantity]').val());
if (!isNaN(currentVal) && currentVal > 0) {
$('input[name=quantity]').val(currentVal - 1);
} else {
$('input[name=quantity]').val(0);
}
});
document.getElementById('buttonFabric').addEventListener("change", function (e) {
canvas.add(new fabric.IText('Tap and Type', {
left: 0,
top: 0,
fontFamily: 'arial black',
fill: '#333',
fontSize: currentVal,
}));
});
解决方案
知道了
$('.qtyplus').click(function(e){
// Stop acting like a button
e.preventDefault();
// Get the field name
// Get its current value
currentVal = parseInt($('input[name=quantity]').val());
// If is not undefined
if (!isNaN(currentVal)) {
// Increment
$('input[name=quantity]').val(currentVal + 1);
if(currentVal!='')
{
var activeObj = canvas.getActiveObject();
//Check that text is selected
if(activeObj==undefined)
{
alert('Please select a Text');
return false;
}
activeObj.set({
scaleX:1,
scaleY:1,
fontSize: currentVal
});
canvas.renderAll();
}
} else {
// Otherwise put a 0 there
$('input[name=quantity]').val(0);
}
});
// This button will decrement the value till 0
$(".qtyminus").click(function(e) {
// Stop acting like a button
e.preventDefault();
// Get the field name
// Get its current value
currentVal = parseInt($('input[name=quantity]').val());
// If it isn't undefined or its greater than 0
if (!isNaN(currentVal) && currentVal > 0) {
// Decrement one
$('input[name=quantity]').val(currentVal - 1);
if(currentVal!='')
{
var activeObj = canvas.getActiveObject();
//Check that text is selected
if(activeObj==undefined)
{
alert('Please select a Text');
return false;
}
activeObj.set({
scaleX:1,
scaleY:1,
fontSize: currentVal
});
canvas.renderAll();
}
} else {
// Otherwise put a 0 there
$('input[name=quantity]').val(0);
}
});
推荐阅读
- docker - hadoop 环境中的 Hue 服务在几秒钟后崩溃
- html - 如何在我项目的所有 .html 中使用导航栏
- css - 有没有办法使用 CSS 为箭头形状添加边框?
- angularjs - AngularJS / rxjs:Observable 在订阅时未捕获错误
- android-studio - 将键盘映射分配给“提取到任意文件”灯泡命题
- python - 我们如何在多个 csv 文件中写入数据范围,并且应该从字典中获取数据
- mongodb - 如何在我试图查找包含查询中所有标签的文档时发出猫鼬查找请求
- api - 使用 API 网关保护云功能
- java - 如何在交换机中创建新对象
- zip - 使用 Pigz 问题压缩目录