0
我有以下JS函数,用于检测图像何时被拖动到HTML5画布上的某个位置:JavaScript:将图像数组绘制到HTML5画布阵列位置时将它们重新排序
function isHit(mouseX, mouseY, obj){
console.log("isHit has been called from within if statement in mousemove function");
console.log("draggingImage variable value = " +draggingImage);
if(draggingImage == true){
console.log("if dragging image == true statment is being called");
console.log("Value of selectedImage = " + selectedImage);
console.log("Value of selectedImageArrayLocation = " + selectedImageArrayLocation);
if(mouseY > 250){
console.log("Value of obj.shape.index = " +obj.shape.index);
if((mouseX > 80) && (mouseX < 200) && (selectedImageArrayLocation >= 0) && (selectedImageArrayLocation <= numImagesAssets)){
console.log("Correct");
document.getElementById('tipsParagraph').innerHTML = "Correct! This is an asset because it is an item that can be bought or sold for cash.";
selectedImage.remove();
console.log("selectedImage has been removed: " + selectedImage);
}else{
console.log("Incorrect");
document.getElementById('tipsParagraph').innerHTML = "Incorrect! This icon is an asset because it is an item that can be bought or sold for cash.";
}
}
}
}
如果图像被拖动到正确的位置,我想从画布中移除它,并为用户提供一些反馈。如果将它拖到错误的位置,我想将图像留在画布上,并向用户提供反馈。
我打电话从我mousemove
功能,当图像被拖动上面的函数(我只要检测到mouseup
每当图像上检测到mousedown
被设置为true,并设置为false一个布尔值。
此刻,当图像被拖动到正确的位置时,它会从画布中移除,并向用户提供反馈,但是阵列中其余图像的位置将被重新排序
我想知道这是因为我上面的函数中的行selectedImage.remove();
是从数组中删除图像,而不是ju st从画布?
我该如何从画布中删除图像,但不是从数组中删除图像,记住我使用KineticJS库将所有图像绘制到画布上?
这是辉煌的,干杯!出于兴趣,只隐藏图像而不去除图像,即使图像不再可见,图像仍然在“画布上”。或者它实际上是从画布上移除的?我注意到当把光标悬停在可见的图像上时,光标从指针变为手指,但是当图像被隐藏时,使用你建议的函数,光标变回到一个指针......大概意思是说图像已从画布中删除? – someone2088 2013-03-20 17:18:13
我假设'hide()'方法就像在CSS中使用'visibility:hidden;':浏览器仍然假装它在那里(其他元素的位置不会改变),但它不会触发任何事件,如鼠标悬停或onclick。 'setOpacity'函数可能会做同样的事情,除了它仍然会在鼠标悬停或点击时触发事件监听器。我不太确定,你必须测试一下。 – 2013-03-20 23:26:30