标题说明了一切。在提供拖动事件时,我遇到了问题。我尝试用 替换mousemove
,mousedown
可能会mousedown
着火一次并安定下来,但它没有帮助。我怎样才能以编程方式做到这一点。
如果您想参考我要操作的代码,您可以参考此代码;否则忽略它:
<script>
$(document).ready(function () {
$(".toolImage").mouseover(function () {
$(this).parent(".toolTip").find(".toolTipDesc").css("display", "block");
});
$(".toolImage").mouseleave(function () {
$(this).parent(".toolTip").find(".toolTipDesc").css("display", "none");
});
var native_width = 0;
var native_height = 0;
//Now the mousemove function
$(".magnify").mousemove(function (e) {
if (!native_width && !native_height) {
//This will create a new image object with the same image as that in .small
//We cannot directly get the dimensions from .small because of the
//width specified to 200px in the html. To get the actual dimensions we have
//created this image object.
var image_object = new Image();
image_object.src = $(".small").attr("src");
native_width = image_object.width;
native_height = image_object.height;
} else {
var magnify_offset = $(this).offset();
var mx = e.pageX - magnify_offset.left;
var my = e.pageY - magnify_offset.top;
//Finally the code to fade out the glass if the mouse is outside the container
if (mx < $(this).width() && my < $(this).height() && mx > 0 && my > 0) {
$(".large").fadeIn(100);
} else {
$(".large").fadeOut(100);
}
if ($(".large").is(":visible")) {
var rx = Math.round(mx / $(".small").width() * native_width - $(".large").width() / 2) * -1;
var ry = Math.round(my / $(".small").height() * native_height - $(".large").height() / 2) * -1;
var bgp = rx + "px " + ry + "px";
//Time to move the magnifying glass with the mouse
var px = (mx - $(".large").width() / 2);
var py = (my - $(".large").height() / 2);
$(".large").css({
left: px,
top: py + 10,
backgroundPosition: bgp
});
}
}
})
$('.t1').mouseenter(function () {
$('.pointerTxt').fadeIn();
});
$('.t1').mouseleave(function () {
$('.pointerTxt').fadeOut();
});
});
</script>