Note that there are some explanatory texts on larger screens.

plurals
  1. POanimating a rectangle with text in Raphael javascript library
    primarykey
    data
    text
    <p>I am quite new to javascript and to Raphael. I am trying to move a button-like rectangle with text inside. Here is my code :</p> <pre><code>window.onload = function() { var paper = new Raphael(document.getElementById('canvas_container'), "100%", "100%"); var box1 = paper.rect(100, 100, 120, 50, 10).attr({fill: 'darkorange', stroke: '#3b4449', 'stroke-width': 2, cursor: 'pointer'}); var box2 = paper.rect(400,100,120,50,10).attr({fill: 'lightblue', stroke: '#3b4449', 'stroke-width': 2}); var text2 = paper.text(box2.attrs.x + box2.attrs.width/2,box2.attrs.y + box2.attrs.height/2,"[x: " + box2.attrs.x + " y: " + box2.attrs.y + "]").attr({"font-family": "arial", "font-size": 16}); var button2 = paper.set(); button2.push(box2); button2.push(text2); box1.click(function(){ // this did not work // button2.animate({x: 100, y: 50 }, 1000, 'bounce', function() { // callback function // text2.attr('text',"[x: " + box2.attrs.x + " y: " + box2.attrs.y + "]"); // }); button2.animate({transform: "t100,100"}, 1000, 'bounce', function() { // callback function text2.attr('text',"[x: " + box2.attrs.x + " y: " + box2.attrs.y + "]"); }); }); } </code></pre> <p>The <code>button2.animate({x: 100, y: 50 }, 1000, 'bounce');</code> line did not worked properly, the text was not in the right position at the end. By using the <code>transform:</code> I can not use coordinates, I would have to compute them. Also I am not able to get the right coordinates of the blue box at the end when using the <code>transform</code> method.</p> <p>I was not able to find any answer yet, hope someone can help me.</p> <p>Thank you</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload