Let's say we have a h1 text, and we want to move it with DOJO to a new position, with a translation animation. We want the new h1 to have the same y coordinate (height from the top), but moved 200 pixels to the right.
fx.slideTo should do the job:
var greetingNode = dom.byId("greeting");
var obj = domGeom.position(greetingNode, true);
fx.slideTo({
node: greeting,
top: obj.y, //pseudocode; obj[1]? obj.Y?
left: obj.x + X //pseudocode; obj[0]? obj.X?
}).play();
I can't manage to access obj correctly. Also, if I print the text coordinates, it appears they are x:8 and y:21.43 periodic. Could you please enlighten me about this?
ps: html.coords would work perfectly, but it is deprecated, and DOJO documentation suggest using dojo.position instead.
Complete code here:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Tutorial: Hello Dojo!</title>
<!-- set Dojo configuration, load Dojo -->
<script>
dojoConfig= {
has: {
"dojo-firebug": true,
"dojo-debug-messages": true
},
async: true
};
</script>
<!-- load Dojo -->
<script src="dojo/dojo.js"
data-dojo-config="async: true"></script>
<script>
require([
"dojo/dom-geometry",
"dojo/dom",
"dojo/dom-style",
"dojo/fx",
"dojo/dom-construct",
"dojo/json",
/*'dojo/_base/html',*/ //required for deprecated html.coords
"dojo/domReady!"
], function (domGeom, dom, style, fx, domConstruct, JSON) {
var greetingNode = dom.byId("greeting");
domConstruct.place("<em> Dojo!</em>", greetingNode);
greeting.innerHTML += " from Dojo!";
/* coords module is deprecated! use position instead
var coords = html.coords(greetingNode);*/
var obj = domGeom.position(greetingNode, true);
dom.byId("divcoordinates").innerHTML = JSON.stringify(obj);
fx.slideTo({
node: greeting,
top: ? //works with coords.y
left: ? //works with coords.x + 200
}).play();
});
</script>
</head>
<body>
<h1 id="greeting">Hello</h1>
<div id="divcoordinates">div coordinates:</div>
</body>
</html>