Skip to content
  • Recent
  • Tags
  • Popular
  • Users
  • Search
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse

Lay Theme Forum

  1. Home
  2. General Discussion
  3. Overlay button

Overlay button

Scheduled Pinned Locked Moved General Discussion
3 Posts 2 Posters 333 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rioma7
    wrote on last edited by
    #1

    Hi there.

    I was wondering how is it possible to add a customized button which is an overlay on any page. I am looking to add something that is similar to the typeface's rectangle that can be moved on this website http://www.collletttivo.it

    Is there someone that can help me? Thanks

    1 Reply Last reply
    0
    • R Offline
      R Offline
      rioma7
      wrote on last edited by
      #2

      I have solved this request by myself but if someone is interested, here is the code I used.

      Custom CSS

      body {
          position: relative;
      }
      #buttonCta {
          position: fixed;
          z-index: 999;
          border-radius: 70px;
          background-color: #0000FF;
          border: 5px solid #F0FCD2;
          text-align: center;
          padding: 12px 25px;
          cursor: move;
      }
      
      #buttonCta     a {
          
              font-family: SpaceMono-Regular;
              color: #F0FCD2;
              text-align: center;
              text-transform: uppercase;
              font-size: 60px;
              cursor: pointer;
       }
       
      #buttonCta:hover {
              background-color: #F0FCD2;
              border: 5px solid #0000FF;
          }
      
          
          #buttonCta:hover a {
              color: #0000FF;
          }
      
       @media only screen and (max-width: 601px) {
             #buttonCta {
              display: none;
             }
          }
      
      

      CUSTOM HEAD CONTENT (JAVASCRIPT)

      <script type="text/javascript">
      document.addEventListener('DOMContentLoaded', () => {
      const cta = document.getElementById("buttonCta");
      
      if((window.innerWidth > 601) && cta) {
          var randomtop = Math.floor(Math.random() * 70);
          var randomleft = Math.floor(Math.random() * 70);
          cta.style.top = `${randomtop}vh`;
          cta.style.left = `${randomleft}vw`;
          dragElement(cta);
      }
      
      console.log(window.innerWidth > 601, cta)
      
      function dragElement(elmnt) {
        var pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0;
      
          elmnt.onmousedown = dragMouseDown;
      
        function dragMouseDown(e) {
          e = e || window.event;
          e.preventDefault();
          // get the mouse cursor position at startup:
          pos3 = e.clientX;
          pos4 = e.clientY;
          document.onmouseup = closeDragElement;
          // call a function whenever the cursor moves:
          document.onmousemove = elementDrag;
        }
      
        function elementDrag(e) {
          e = e || window.event;
          e.preventDefault();
          // calculate the new cursor position:
          pos1 = pos3 - e.clientX;
          pos2 = pos4 - e.clientY;
          pos3 = e.clientX;
          pos4 = e.clientY;
          // set the element's new position:
          elmnt.style.top = (elmnt.offsetTop - pos2) + "px";
          elmnt.style.left = (elmnt.offsetLeft - pos1) + "px";
        }
      
        function closeDragElement() {
          /* stop moving when mouse button is released:*/
          document.onmouseup = null;
          document.onmousemove = null;
        }
      }
      });
      </script>
      
      

      CUSTOM HTML TOP

      <div id="buttonCta">
          <a href="LINK">TEXT ON THE BUTTON</a>
      </div>
      
      1 Reply Last reply
      1
      • RichardR Offline
        RichardR Offline
        Richard
        Global Moderator
        wrote on last edited by
        #3

        @rioma7 Awesome! Upvote from me :)

        have a great day

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        I also code custom websites or custom Lay features.
        šŸ’æ Email me here: šŸ’æ
        info@laytheme.com

        Before you post:
        1. When using a WordPress Cache plugin, disable it or clear your cache.
        2. Update Lay Theme and all Lay Theme Addons
        3. Disable all Plugins
        4. Go to Lay Options → Custom CSS & HTML, click "Turn Off All Custom Code", click "Save Changes"

        This often solves issues you might run into

        When you post:
        1. Post a link to where the problem is
        2. Does the problem happen on Chrome, Firefox, Safari or iPhone or Android?
        3. If the problem is difficult to explain, post screenshots / link to a video to explain it
        Online Users
        B
        barrybianco
        E
        eduardocaballero
        Forgot your key, lost your files, need a previous Lay Theme or Addon version? Go to www.laykeymanager.com
        laytheme.com
        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Recent
        • Tags
        • Popular
        • Users
        • Search