1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

I need to create a draggable popup layer. Help.

Discussion in 'HTML & Website Design' started by SoftLink, Apr 25, 2024.

  1. #1
    I need to be able to create a popup that is mouse/touch draggable.
    It needs to be prevented from being able to be moved out of the viewport.

    I've tried for hours.
    I'm hoping somebody knows of existing code or knows how to do it.

    Help would be appreciated.
     
    SoftLink, Apr 25, 2024 IP
  2. ypkush

    ypkush Well-Known Member

    Messages:
    48
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    111
    #2
    Hi
    Looking for like this?
    https://ej2.syncfusion.com/aspnetmvc/Dialog/Draggable#/material3
     
    ypkush, Apr 25, 2024 IP
  3. SoftLink

    SoftLink Active Member

    Messages:
    106
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    60
    #3
    ypkush: Thanks but no, that's a drag function. I need something that will make the element follow the mouse, not a drag.
    When I mouseup the element needs to stop where ever it is, not a drop.
    Also, when the mouse runs out of the viewport the element needs to recognize that as a mouse up and not take the element out of the viewport.
     
    SoftLink, Apr 26, 2024 IP
  4. ypkush

    ypkush Well-Known Member

    Messages:
    48
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    111
    #4
    This may help for you, here is the example
    https://codepen.io/lfry/pen/AEqKRM
    https://www.kirupa.com/canvas/follow_mouse_cursor.htm
     
    ypkush, May 2, 2024 at 2:15 AM IP
  5. SoftLink

    SoftLink Active Member

    Messages:
    106
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    60
    #5
    ypkush: Thanks again for your response.
    Still, this isn't quite it.

    I did learn of this function from it: requestAnimationFrame which I believe I can use.

    I can make an element follow a mouse and I can make it stop and stay on mouseup (not a drop).
    BUT when the mouse goes out of the viewport the element flips out.
    I want it to follow a page scroll but when the mouse is out of the viewport and off the page the element should just stop.

    I'm hoping requestAnimationFrame will help with the page scroll problems at least and that *may* solve the whole problem.

    Again, thanks for your help.
     
    SoftLink, May 2, 2024 at 4:06 AM IP
  6. qwikad.com

    qwikad.com Illustrious Member Affiliate Manager

    Messages:
    7,156
    Likes Received:
    1,660
    Best Answers:
    29
    Trophy Points:
    475