[英]How to drag an image to move it smoothly on screen, using jquery in ie8
I am working on a project where we can move an image like in google map,, it works perfectly in crome,ff and above ie9, but when i checked in ie8 the image is not moving smoothly,it takes a 2 to 3 sec of time to move. 我正在一个项目中,我们可以像在谷歌地图中一样移动图像,它在crome,ff和ie9以上都可以完美运行,但是当我在ie8中签入时,图像不能平稳移动,需要2到3秒的时间该移动了。
/* Map dragging */
var previousX;
var previousY;
var previousLeft;
var previousTop;
var cids = self.data.cuLocation;
var lumids = self.data.lumLocation;
$('#MapView img').css( 'cursor', 'pointer' );
$("#MapView img").mousedown(function(e) {
//console.log("mousedown");
e.preventDefault();
drag.state = true;
previousX = e.originalEvent.clientX;
previousY = e.originalEvent.clientY;
previousLeft = $("#MapView img").position().left;
previousTop = $("#MapView img").position().top;
});
$("#MapView img").mousemove(function(e) {
var old_pos = self.getPosition();
if (drag.state) {
e.preventDefault();
drag.x = e.originalEvent.clientX - previousX;
drag.y = e.originalEvent.clientY - previousY;
var cur_position = $("#MapView img").position();
var new_left = cur_position.left + drag.x;
var new_top = cur_position.top + drag.y;
previousX = e.originalEvent.clientX;
previousY = e.originalEvent.clientY;
}
});
$("#MapView img").mouseleave(function(e) {
//console.log("mouseleave");
drag.state = false;
});
$(document).mouseup(function(e) {
// alert("mouseup");
drag.state = false;
});
Use the following Link for your better understanding in Draggable event so than you can use it to Drag your Image wherever you want. 使用以下链接可以更好地理解Draggable事件,而不是将其用于将图像拖到任何位置。 http://jqueryui.com/draggable/
http://jqueryui.com/draggable/
and for Drap & Drop of one element onto other element :: http://jqueryui.com/draggable/#snap-to 并将一个元素拖放到另一元素上:: http://jqueryui.com/draggable/#snap-to
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.