0

I am looking at creating a webpage with user feedback where the user can click within a certain element of the page, which brings up a comment box for the user to enter details, if the user left a note a post-it note would be left where they clicked. this note indication has to move when the user scrolls so that the note does not move away from the element it was left on.

Is this possible? I have been trying to search this on google but I only seem to get how to disable right click.

If it is possible where could I find the relevant information.

Cheers

NoLiver92
  • 882
  • 3
  • 15
  • 39

2 Answers2

1

To get via JS the coordinates where a user has clicked:

(function() {
    window.onmousedown = handleMouseMove;
    function handleMouseMove(event) {
        event = event || window.event; // IE-ism
        console.log(event.clientX);
        console.log(event.clientY);
    }
})();

Here you have an example of how to move a DIV where user clicks:

(function() {
    window.onmousedown = handleMouseMove;
    function handleMouseMove(event) {
        event = event || window.event; // IE-ism
        console.log(event.clientX);
        moveDiv(event.clientX,event.clientY);
    }
})();

    function moveDiv(x_pos,y_pos){
        var d = document.getElementById('myDiv');
        d.style.left = x_pos + "px";
        d.style.top = y_pos + "px";
    }

Example

Rafa Romero
  • 2,667
  • 5
  • 25
  • 51
  • 1
    that looks good, but if im including an iframe which shows another webpage (also mine) I am assuming that this code would have to be on the embedded website rather than on the main one? – NoLiver92 Jun 03 '14 at 13:44
  • 1
    Yes you are right. If the element itself is in the embedded website, you should include that code on the embedded one – Rafa Romero Jun 03 '14 at 13:45
0

First, get mouse click coordinates: getting the X/Y coordinates of a mouse click on an image with jQuery

Than put element with 'position: absolute' at specified location.

Community
  • 1
  • 1
Justinas
  • 41,402
  • 5
  • 66
  • 96