Click and hold event Javascript [closed]

末鹿安然 提交于 2019-12-11 16:22:14

问题


I havent gotten started on the project I'm going to be working on, but in planning I'm having trouble figuring out a click and hold event issue.

I am going to be having a click through div (a div that is over the image element, yet I can still click on the image) with an opacity somewhere around 0.7 with an image below it. I will be able to click on the image and move it around on a canvas (basically just move it from one side of the canvas to the other).

Does anyone know of a way to create a click and hold event where when I am clicking on the image to move it on the canvas, the click through divs opacity becomes 0 (or the div become hidden all together), then when i un-click it goes back to 0.7?

Thanks!


回答1:


Please try this

I have created a DEMO . This is what I understood from your question. If this is not what you meant please add some html or code you have tried so that its easy to understand your problem.

$(document).ready(function(){
    $("img").mouseup(function(){
        $("#containment-wrapper").css("background-color", "black");
    });
    $("img").mousedown(function(){
        $("#containment-wrapper").css("background-color", "white");
    });
});



回答2:


What about jQuery's https://api.jquery.com/mousemove/ ? In the Doc they have an example how to bind the even to a target:

$( "#target" ).mousemove(function( event ) {
    var msg = "Handler for .mousemove() called at ";
    msg += event.pageX + ", " + event.pageY;
    $( "#log" ).append( "<div>" + msg + "</div>" );
});


来源:https://stackoverflow.com/questions/31398294/click-and-hold-event-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!