JavaScript Drag & Select functionality done right

后端 未结 4 975
长情又很酷
长情又很酷 2020-12-23 23:08

I\'m trying to write a drag & select functionality using HTML & JavaScript. By that I mean that there will be a set of objects with arbitrary absolute positions. I w

4条回答
  •  Happy的楠姐
    2020-12-23 23:58

    The main problem is suppressing actual text selection, which seems kind of against the very nature of a web browser.

    The function you are looking for is e.preventDefault();

    $("#inputform").mousedown(function(e){
        e.preventDefault();
        //console.log('mousedown');
    }).mouseup(function(e){
        e.preventDefault();
        //console.log('mouseup');
    });
    

    This just solves the problem of text selection. I can see various drag-select js scritps across the web but somehow I am unable to make them work.

提交回复
热议问题