
Cambiar el ancho de una imagen SVG en Canvas con un select y un botón
Publicado por Javier (1 intervención) el 05/07/2017 10:20:50
Hola, estoy intentando modificar el ancho de una imagen SVG en un canvas usando un select y un botón con librería fabric.js. Me he atascado con el código. Agradecería si alguien me pudiera echar una mano. Saludos
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<html>
<head>
<script src="fabric.js"></script>
</head>
<body>
<canvas id="c" width="800" height="450" style="border:1px solid #000000"></canvas>
<div style="display: inline-block; width: 140px">
<select id="ancho">
<option>106</option>
<option>150</option>
<option>200</option>
</select>
<button id="Ancho">Ancho</button>
</div>
<script>
var canvas = this.__canvas = new fabric.Canvas('c', { selection: false });
fabric.Object.prototype.originX = fabric.Object.prototype.originY = 'center';
fabric.Image.fromURL('ventana.svg', function(vent) {
vent.scale(2);
vent.setLeft(380);
vent.setTop(200);
canvas.add(vent);
});
var selectancho = document.getElementById('ancho').value;
var AnchoBtn = document.getElementById('Ancho');
AnchoBtn.onclick = function() {
selectancho = document.getElementById('ancho').value;
vent.set('width', selectancho);
canvas.renderAll();
};
</script>
</body>
</html>
Valora esta pregunta


0