cl92
cl92

Reputation: 3

Change from mouseDown to OnClick

I have a functioning code that allows me to drag down and reveal but I want it to be on click instead of moving the mousedown. JQuery has never been my strong suit. Here is the code:

<script>
    var div = document.getElementById("drag");
    var outer = document.getElementById("container");
    var start = div.style.top;
    var end = start + 100;
    window.onload = addListeners;

    function addListeners() {
        div.addEventListener('mousedown', mouseDown, false);
        window.addEventListener('mouseup', mouseUp, false);
    }

    function mouseUp() {
        window.removeEventListener('mousemove', divMove, true);
    }

    function mouseDown(e) {
        window.addEventListener('mousemove', divMove, true);
    }

    function divMove(e) {
        if (e.clientY < end && e.clientY >= start) {
            div.style.top = e.clientY - 70 + 'px';
        }
</script>

Upvotes: 0

Views: 269

Answers (1)

Dan Oswalt
Dan Oswalt

Reputation: 2189

I think all you'll need to do is change mousedown to click, if I'm understanding...

Upvotes: 2

Related Questions