- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试在动画期间更改组内的文本。您可以在下面代码段的控制台中看到这一点,
group.item(2).setText(Math.floor(count * 10) % 2 === 0 ? "O" : "X");
parseInt(count + "") % 2 === 0
可能是管理翻转硬币文本的正确方式,但不幸的是它不起作用。谁能帮我理解为什么硬币的一面没有翻转?
var fabric;
(function(fabric) {})(fabric || (fabric = {}));
fabric.Background = fabric.util.createClass(fabric.Rect, {
type: "background",
initialize: function(options) {
options = options || {};
this.callSuper("initialize", options);
},
_render: function(ctx) {
this.callSuper("_render", ctx);
}
});
var Ys = (function() {
function Ys() {
var _this = this;
this.app = new fabric.Canvas(document.getElementById("c"));
this.renderHexagram = function() {};
this.resize = function() {
var w = (window.innerWidth > 0) ? window.innerWidth : screen.width;
var h = (window.innerHeight > 0) ? window.innerHeight : screen.height;
var width = w;
var height = h;
_this.app.setDimensions({
width: width,
height: height
});
};
this.drawBackground = function() {
var backgroundOptions = {};
backgroundOptions.width = _this.app.getWidth();
backgroundOptions.height = _this.app.getHeight();
backgroundOptions.selectable = false;
var background = new fabric.Background(backgroundOptions);
var gradientOptions = _this.createVerticalGradientOptions("linear", _this.app.getHeight(), {
0: "#333333",
1: "#222222"
});
background.setGradient("fill", gradientOptions);
_this.background = background;
_this.app.add(background);
};
this.drawToss = function() {
[1, 1, 1].forEach(function(item, idx) {
setTimeout(function() {
_this.toss(idx);
}, _this.getRandom(1, 10) * 100);
});
};
this.toss = function(idx) {
var canvas = _this.app;
var circle = new fabric.Circle({
left: 0,
top: 0,
radius: (_this.app.getWidth() / 5) / 2,
fill: "#FFE600",
stroke: "#CACA3B",
strokeWidth: 1,
angle: 0,
padding: 0,
originX: "center",
originY: "center"
});
var innerCircle = new fabric.Circle({
left: 0,
top: 0,
radius: (_this.app.getWidth() / 6) / 2,
fill: "#FFFF00",
stroke: "#CACA3B",
strokeWidth: 1.5,
angle: 0,
padding: 0,
originX: "center",
originY: "center"
});
var text = new fabric.Text("", {
left: 0,
top: 0,
angle: 90,
originX: "center",
originY: "center",
fill: "#fffdb5",
stroke: "#CACA3B",
fontSize: ((_this.app.getWidth() / 5)),
fontWeight: 700,
strokeWidth: 1
});
var group = new fabric.Group([circle, innerCircle, text], ({
left: (_this.app.getWidth() / 6) + ((_this.app.getWidth() / 3) * idx),
top: -((_this.app.getWidth() / 5) / 2),
originX: "center",
originY: "center",
selectable: true,
hasControl: true
}));
var rotateIntervall = setInterval((function() {
var f = 0;
return function() {
group.angle = f;
if (f > 180) {
f = 0;
} else {
f += 1;
}
canvas.renderAll();
};
})(), 0);
group.animate("top", _this.app.getHeight() - ((_this.app.getWidth() / 5) / 2), {
duration: 600,
onChange: canvas.renderAll.bind(canvas),
easing: fabric.util.ease["easeOutBounce"]
});
(function rotate(f, count) {
count += .01;
console.log(Math.floor(count * 10));
group.item(2).setText(Math.floor(count * 10) % 2 === 0 ? "O" : "X");
var skewInterval = setInterval((function() {
return function() {
group.transformMatrix = [0, 1, f, 0, 0, 0];
if (f > 1 && count >= 10) {
clearInterval(skewInterval);
clearInterval(rotateIntervall);
return 0;
} else if (f > 1) {
f = 0;
} else if (f > 0.8) {
f += 0.03;
} else if (f > 0.9) {
if (f > 0.93) {
f += 0.04;
} else if (f > 0.96) {
f += 0.05;
} else {
f += 0.06;
}
} else {
f += 0.09;
}
canvas.renderAll();
clearInterval(skewInterval);
rotate(f, count);
return 0;
};
})(), count);
})(0, 0);
canvas.add(group);
};
this.resize();
this.app.renderOnAddRemove = true;
this.headerHeight = this.app.getHeight() / 12;
this.drawBackground();
this.drawToss();
}
Ys.prototype.createVerticalGradientOptions = function(type, height, colorStops) {
return {
type: type,
x1: 0,
y1: 0,
x2: 0,
y2: height,
colorStops: colorStops
};
};
Ys.prototype.getRandom = function(min, max) {
return Math.random() * (max - min) + min;
};
return Ys;
}());
var ys = new Ys();
//# sourceMappingURL=application.js.map
* {
padding: 0;
margin: 0;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/1.7.2/fabric.min.js"></script>
<canvas id="c" width="100" height="100"></canvas>
最佳答案
肯定是缓存尝试有问题:
fabric.Object.prototype.objectCaching = false;
var fabric;
(function(fabric) {})(fabric || (fabric = {}));
fabric.Background = fabric.util.createClass(fabric.Rect, {
type: "background",
initialize: function(options) {
options = options || {};
this.callSuper("initialize", options);
},
_render: function(ctx) {
this.callSuper("_render", ctx);
}
});
var Ys = (function() {
function Ys() {
var _this = this;
this.app = new fabric.Canvas(document.getElementById("c"));
this.renderHexagram = function() {};
this.resize = function() {
var w = (window.innerWidth > 0) ? window.innerWidth : screen.width;
var h = (window.innerHeight > 0) ? window.innerHeight : screen.height;
var width = w;
var height = h;
_this.app.setDimensions({
width: width,
height: height
});
};
this.drawBackground = function() {
var backgroundOptions = {};
backgroundOptions.width = _this.app.getWidth();
backgroundOptions.height = _this.app.getHeight();
backgroundOptions.selectable = false;
var background = new fabric.Background(backgroundOptions);
var gradientOptions = _this.createVerticalGradientOptions("linear", _this.app.getHeight(), {
0: "#333333",
1: "#222222"
});
background.setGradient("fill", gradientOptions);
_this.background = background;
_this.app.add(background);
};
this.drawToss = function() {
[1, 1, 1].forEach(function(item, idx) {
setTimeout(function() {
_this.toss(idx);
}, _this.getRandom(1, 10) * 100);
});
};
this.toss = function(idx) {
var canvas = _this.app;
var circle = new fabric.Circle({
left: 0,
top: 0,
radius: (_this.app.getWidth() / 5) / 2,
fill: "#FFE600",
stroke: "#CACA3B",
strokeWidth: 1,
angle: 0,
padding: 0,
originX: "center",
originY: "center"
});
var innerCircle = new fabric.Circle({
left: 0,
top: 0,
radius: (_this.app.getWidth() / 6) / 2,
fill: "#FFFF00",
stroke: "#CACA3B",
strokeWidth: 1.5,
angle: 0,
padding: 0,
originX: "center",
originY: "center"
});
var text = new fabric.IText("", {
left: 0,
top: 0,
angle: 90,
originX: "center",
originY: "center",
fill: "#fffdb5",
stroke: "#CACA3B",
fontSize: ((_this.app.getWidth() / 6)),
fontFamily: "Segoe UI",
fontWeight: 700,
strokeWidth: 1
});
var group = new fabric.Group([circle, innerCircle, text], ({
left: (_this.app.getWidth() / 6) + ((_this.app.getWidth() / 3) * idx),
top: -((_this.app.getWidth() / 5) / 2),
originX: "center",
originY: "center",
selectable: true,
hasControl: true
}));
var rotateIntervall = setInterval((function() {
var f = 0;
return function() {
group.angle = f;
if (f > 180) {
f = 0;
} else {
f += 1;
}
canvas.renderAll();
};
})(), 0);
group.animate("top", _this.app.getHeight() - ((_this.app.getWidth() / 5) / 2), {
duration: 600,
onChange: canvas.renderAll.bind(canvas),
easing: fabric.util.ease["easeOutBounce"]
});
(function rotate(f, count) {
count += .01;
group.item(2).set({
text: Math.floor(count * 10) % 2 === 0 ? "I" : "O"
});
var skewInterval = setInterval((function() {
return function() {
group.transformMatrix = [0, 1, f, 0, 0, 0];
if (f > 1 && count >= 10) {
clearInterval(skewInterval);
clearInterval(rotateIntervall);
return 0;
} else if (f > 1) {
f = 0;
} else if (f > 0.8) {
f += 0.03;
} else if (f > 0.9) {
if (f > 0.93) {
f += 0.04;
} else if (f > 0.96) {
f += 0.05;
} else {
f += 0.06;
}
} else {
f += 0.09;
}
canvas.renderAll();
clearInterval(skewInterval);
rotate(f, count);
return 0;
};
})(), count);
})(0, 0);
canvas.add(group);
};
fabric.Object.prototype.objectCaching = false;
this.resize();
this.app.renderOnAddRemove = true;
this.headerHeight = this.app.getHeight() / 12;
this.drawBackground();
this.drawToss();
}
Ys.prototype.createVerticalGradientOptions = function(type, height, colorStops) {
return {
type: type,
x1: 0,
y1: 0,
x2: 0,
y2: height,
colorStops: colorStops
};
};
Ys.prototype.getRandom = function(min, max) {
return Math.random() * (max - min) + min;
};
return Ys;
}());
var ys = new Ys();
//# sourceMappingURL=application.js.map
* {
padding: 0;
margin: 0;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/1.7.2/fabric.min.js"></script>
<canvas id="c" width="100" height="100"></canvas>
关于javascript - 在 fabricjs 上下文中更改文本不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41473941/
今天有小伙伴给我留言问到,try{...}catch(){...}是什么意思?它用来干什么? 简单的说 他们是用来捕获异常的 下面我们通过一个例子来详细讲解下
我正在努力提高网站的可访问性,但我不知道如何在页脚中标记社交媒体链接列表。这些链接指向我在 facecook、twitter 等上的帐户。我不想用 role="navigation" 标记这些链接,因
说现在是 6 点,我有一个 Timer 并在 10 点安排了一个 TimerTask。之后,System DateTime 被其他服务(例如 ntp)调整为 9 点钟。我仍然希望我的 TimerTas
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我就废话不多说了,大家还是直接看代码吧~ ? 1
Maven系列1 1.什么是Maven? Maven是一个项目管理工具,它包含了一个对象模型。一组标准集合,一个依赖管理系统。和用来运行定义在生命周期阶段中插件目标和逻辑。 核心功能 Mav
我是一名优秀的程序员,十分优秀!