UPDATE
I'm using Raphael Freetransform to show imgs from user upload,
searching for a long time, how to do below thing
1) click
toggle showhandle``hidehandle
? solved
2) Add a new button each time new Freetransform object be create.
- Click the button object can be remove.
3) Raphael object can use toFront
, Freetransform how to do it
use Raphael Freetransform basic coding:
var paper = Raphael($('.canvas')[0], 1000, 1000);
var r_img = paper.image('img/path'+file_type, 100, 100, 200, 200);
paper.freeTransform(r_img).setOpts({drag:'self', scale:true, rotate:true, draw:[ 'bbox' ], keepRatio: true});
after user upload 2 img in canvas, the output source code will be:
<image></image>
<image></image>
// 1st image handle
<path></path>
<circle></circle>
<path></path>
<circle></circle>
<path></path>
<rect></rect> // x8
// 2nd image handle
<path></path>
<circle></circle>
<path></path>
<circle></circle>
<path></path>
<rect></rect> // x8
solve the question 2)
if I create a div tag be button, I can't find 1 group(image and handle) be select.
solve the question 3)
if click
, the image
can use toFront
resoure, but the handle how to be front too?
img.onload = function(){
var img_width = this.width, img_height = this.height;
var img_scale = img_width / 200;
var new_height = img_height / img_scale;
var ft, r_img = paper.image('img/'+path, 0, 0, 200, new_height), dragged = false;
r_img.click(function(){
// Toggle handles on click if no drag occurred
if(!dragged){
if( ft.handles.center === null){
ft.showHandles();
console.log('front');
r_img.toFront();
//r_img.remove();
}else{
ft.hideHandles();
}
}
});
ft = paper.freeTransform(r_img, {draw:[ 'bbox' ], keepRatio: true, size: 3 }, function(ft, events){
if(events.indexOf('drag start') !== -1){
dragged = false;
}
if(events.indexOf('drag') !== -1){
dragged = true;
}
});
};
img.src = 'img/'+path;