Skip to content

hover link effect

Solved Customisation
  • With my code the only problem is I have the same effect on images (on mouse hover) that contain a url.

    Do you have a solution to fix this @phenomlab ?

  • @DownPW I had exactly the same issue. Before I provide my solution, from recollection, you are using Fancybox ?

  • @DownPW in that case, youā€™ll need to add the below jQuery function just after the one you should already have

        $(window).on('action:posts.loaded', function(data) {
            console.log("Polling DOM for lazyLoaded images to apply Fancybox");
            $(document).ready(function() {
                $('a').not('.forum-logo').not(".avatar").not(".emoji").not(".bmac-noanimate").each(function() {
                    $('a[href*=".jpg"], a[href*=".jpeg"], a[href*=".png"], a[href*=".gif"], a[href*=".webp"]').addClass("noanimate");
                });
            });
        });
    

    What we are doing here is polling the DOM looking for any new images as posts are being loaded (hence the hook action:posts.loaded, and then it we get a match, we add new class .noanimate. Youā€™ll need to modify your existing class block you are using for the hover effect so that it is not being executed against any HTML that contains this class - see below for an example (in your use case)

    .posts .content a:not(.noanimate) {
      background-image: linear-gradient(to right, #54b3d6, #54b3d6 50%, #337ab7 50%);
      background-size: 200% 100%;
      background-position: -100%;
      display: inline-block;
      padding: 5px 0;
      position: relative;
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;
      transition: all 0.3s ease-in-out;
    }
    
  • @phenomlab

    Thanks dude I will test that

  • @phenomlab said in hover link effect:

    .posts .content a:not(.noanimate) {
    background-image: linear-gradient(to right, #54b3d6, #54b3d6 50%, #337ab7 50%);
    background-size: 200% 100%;
    background-position: -100%;
    display: inline-block;
    padding: 5px 0;
    position: relative;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    transition: all 0.3s ease-in-out;
    }

    itā€™s worked, thank you.

  • Hello āœ‹

    I play with URL/Link CSS Trick for topic on nodebb V3

    Here are 3 effects I love that I share with you I love the first one and I think itā€™s the one Iā€™d keep in production.

    ā€“ Style 1 :

    test.gif

    .posts .content a {
        box-shadow: inset 0 0 0 0 var(--bs-link-color);
        color: var(--bs-link-color);
        padding: 0 .25rem;
        margin: 0 -.25rem;
        transition: color .3s ease-in-out, box-shadow .3s ease-in-out;
        border-radius: 0.5rem;
    }
    
    .posts .content a:hover {
        color: #fff;
        box-shadow: inset 200px 0 0 0 var(--bs-link-color);
        border-radius: 0.5rem;
    }
    
    .posts .content a:hover::before{
        width: 100%;
    } 
    

    ā€“ Style 2 :

    test2.gif

     .posts .content a {
        color: var(--bs-link-color);
        background-image: linear-gradient(to right, var(--bs-link-color), var(--bs-link-color) 50%, var(--bs-link-hover-color) 50%);
        background-size: 200% 100%;
        background-position: -100%;
        display: inline-block;
        padding: 5px 0;
        position: relative;
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
        transition: all 0.3s ease-in-out;
    }
    
    .posts .content a:hover {
     background-position: 0;
    }
    
    .posts .content a:hover::before{
        width: 100%;
    }
    

    ā€“ Style 3 :

    test3.gif

    .posts .content a {
        color: var(--bs-link-color);
        text-decoration: none;
        background: linear-gradient(to right, var(--bs-link-color), var(--bs-link-color)), linear-gradient(to right, var(--bs-link-hover-color), var(--bs-link-hover-color), var(--bs-link-hover-color));
        background-size: 100% 3px, 0 3px;
        background-position: 100% 100%, 0 100%;
        background-repeat: no-repeat;
        transition: background-size 400ms;
        padding-bottom: 3px;
    }
    
    .posts .content a:hover {
     background-size: 0 3px, 100% 3px;
    }
    
    .posts .content a:hover::before{
        width: 100%;
    }
    

    ā€“> Itā€™s up to you to play with colors, adapt the code to your environment etc.

    Have fun šŸ˜‰

  • @DownPW these look great! Thanks for sharing.

  • Hello !!!

    I search to have this hover link effect on nodebb without success.
    If anyone has an idea, Iā€™m a taker.

    go to the download button

    https://www.warp.dev

  • @DownPW Looking at the underlying code, class start is being added on hover by jQuery in this function

    
      document.querySelectorAll(".button-gradient, .button-transparent").forEach((button) => {
        const style = getComputedStyle(button);
    
        const lines = document.createElement("div");
    
        lines.classList.add("lines");
    
        const groupTop = document.createElement("div");
        const groupBottom = document.createElement("div");
    
        const svg = createSVG(
          button.offsetWidth,
          button.offsetHeight,
          parseInt(style.borderRadius, 10)
        );
    
        groupTop.appendChild(svg);
        groupTop.appendChild(svg.cloneNode(true));
        groupTop.appendChild(svg.cloneNode(true));
        groupTop.appendChild(svg.cloneNode(true));
    
        groupBottom.appendChild(svg.cloneNode(true));
        groupBottom.appendChild(svg.cloneNode(true));
        groupBottom.appendChild(svg.cloneNode(true));
        groupBottom.appendChild(svg.cloneNode(true));
    
        lines.appendChild(groupTop);
        lines.appendChild(groupBottom);
    
        button.appendChild(lines);
    
        button.addEventListener("pointerenter", () => {
          button.classList.add("start");
        });
    
        svg.addEventListener("animationend", () => {
          button.classList.remove("start");
        });
      });
    })
    

    The CSS for start is below

    .button-gradient.start .lines svg, .button-transparent.start .lines svg {
      animation: stroke 0.3s linear;
    }
    

    And this is the corresponding keyframe

    @keyframes stroke {
      30%, 55% {
        opacity: 1;
      }
      100% {
        stroke-dashoffset: 5;
        opacity: 0;
      }
    }
    

    Itā€™s using both CSS and SVG, so might not be a simple affair to replicate without the SVG files.


Did this solution help you?
Did you find the suggested solution useful? Why not buy me a coffee? It's a nice gesture, and a great way to show your appreciation šŸ’—

Related Topics