What I have is:
What I am trying to do is:
What I want to achieve:
How do I achieve this ?
Some Code :
Fiddle Link : here
$("img").bind("touchmove",function(event) {
e=event.originalEvent;
x1 = e.pageX;
y1 = e.pageY;
x = x1 - x0;
y = y1 - y0;
r = 180 - ((180/Math.PI) * Math.atan2(y,x));
$("#marker").css('-webkit-transform','rotate(-'+r+'deg) translate(-160px)');
// Code to show values of Pie as a tooltip or in a separate div
});
Surprisingly, your problem can be solved with CSS only (note, I haven't checked if this works in a touch device, but it should):
area {
display:block;
position: absolute;
}
area:after {
background: red;
color: white;
position: absolute;
display: block;
white-space: nowrap;
}
area:hover:after {
content: attr(title);
}
However, if you want to keep javascript for flexibility, you don't really need to check the dragging state since touchmove implies that the finger is pressed. You shouldn't need the nested window load event (which doesn't fire in Chrome, anyways). This simplifies the code a bit.
$(document).ready(function(){
var angle=180;
var x0, y0;
var x, y, x1, y1, drag = 0;
var content=$("#content");
var img=$("#myimage");
var imgpos = img.position();
var marker = $("#marker");
var info = $("#info");
$(document).bind('touchmove touchstart',function(e){
e.originalEvent.preventDefault();
});
img.removeAttr("width");
img.removeAttr("height");
x0 = imgpos.left + (img.width() / 2);
y0 = imgpos.top + (img.height() / 2);
content.on("touchmove mousemove", "map", function(event) {
e=event.originalEvent;
x1 = e.pageX;
y1 = e.pageY;
x = x1 - x0;
y = y1 - y0;
r = 180 - ((180/Math.PI) * Math.atan2(y,x));
marker.css('-webkit-transform','rotate(-'+r+'deg) translate(-160px)');
info.text(event.target.getAttribute('title'));
});
});
You can see both implementations in action here: http://jsfiddle.net/Wz7fF/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With