Effortlessly creating a sine wave effect for a link underline on hover using CSS and jQuery

Here is an example:

$(function(){
        var x = 0;
        setInterval(function(){
            x-=1;
            $(".link-wavy:hover").css('background-position', x + 'px 100%');
        }, 20);
    })
body {
  font-family: 'Source Sans Pro', sans-serif;
  color: #000;
  font-size: 1em;
  line-height: 1.6em;
  font-weight: 400;
}

a {
  text-decoration: none;
}

.link-contact {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  overflow: hidden;
  color: #000;
}

.link-wavy {
  padding-bottom: 9px;
  background-image: url("http://uploads.webflow.com/56d8a8f1100bc1bb7928eebd/5831d10096c13a1f491ac02d_wavy-k.png");
  background-position: -50px 100%;
  background-size: 230px;
  background-repeat: repeat-x;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a class="link-contact w-inline-block" href="http://google.com">
    <div class="link-wavy">wavvvvvvy baby</div>
  </a>

This code demonstrates moving the background image continuously on hover for a wave effect.

However, I am seeking more advanced techniques in jQuery to enhance this motion. Specifically, adding ease in-out on hover and ensuring the wave starts where it stops when no longer hovered over (to avoid a sudden jump reset).

If you have any suggestions or ideas, they would be greatly appreciated. Thank you!

Answer №1

Regarding CSS animation techniques, the following code snippet demonstrates how to achieve a wavy effect:

example

.link-wavy {
  animation: wavit 2s linear infinite;
  animation-play-state: paused;
}
.link-wavy:hover {
  animation-play-state: running;
}
@keyframes wavit {
  to {
    background-position: 100% 100%;
  }
}


body {
  font-family: 'Source Sans Pro', sans-serif;
  color: #000;
  font-size: 1em;
  line-height: 1.6em;
  font-weight: 400;
  min-height: 100vh;
  width: 100%;
}

/* added some flex instead absolute + transform */
html,
body {
  display: flex;/* to center demo */
}
.link-contact {
  margin: auto;/* flex item centers itself */
  color: #000;
}
a {
  text-decoration: none;
}
.link-wavy {
  padding-bottom: 9px;
  background-image: url("http://uploads.webflow.com/56d8a8f1100bc1bb7928eebd/5831d10096c13a1f491ac02d_wavy-k.png");
  background-position: 0 100%;
  background-size: 230px;
  background-repeat: repeat-x;
}
<a class="link-contact w-inline-block" href="http://google.com">
  <div class="link-wavy">wavvvvvvy baby</div>
</a>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The sorting function is failing to produce the expected order of values

Currently, I am working on a feature to sort an array of objects based on user-selected values. Strangely, the function returns the same result no matter which case is executed. I have thoroughly checked each case and they are functioning correctly; howeve ...

Issue with loading Babel preset in a monorepo setup

I'm working with a monorepo setup using Lerna and it's structured as follows: monorepo |-- server |-- package1 |-- package2 All packages in the repo make use of Babel. After installing all 3 projects, yarn copied all the required @babe ...

Tips on how to retrieve the value of a number-type input within a custom attribute directive

I have successfully implemented this code in IE 11, but now we are looking to transition away from IE11 and address some of the issues that have arisen. <input type="number" evaluate-input="model.personalNumber" ng-model="model ...

Struggling to store a new user in Firebase Database

I have been researching extensively and am struggling to get any data to show up in the firebase database. I am aiming for this specific structure: "my-app-name": { "users": { "uid-of-user": { "email": "<a href="/cdn-cgi/l/email ...

Transforming a variable into a class using JavaScript and Node

Hey there, back with another question. I have a new variable in NodeJS called Blessed that looks like this: var box = blessed.box({ width: '100%', height: 1, content: someContent, tags: true, style: { fg: 'white', bg: ...

Utilizing numerous script elements for three.js library

Today, I ventured into the world of three.js for the first time, along with exploring html and js in general. While experimenting with some example code, I encountered an issue. It seems that importing the three.js file from the script tag in my Main.js ...

Utilize an AngularJS controller to verify the presence of a cookie and display a modal pop-up

In the process of developing a Single Page Application (SPA), I have encountered an issue with an HTML element calling an AngularJS controller. Here is what I need: I want the controller to check for a specific cookie: - If the cookie exists, call a ...

Pagination in DynamoDB: Moving forward and backward through your data

Currently, I am utilizing DynamoDB in combination with NodeJS to display a list of objects on the user interface. Given that DynamoDB can only process 1MB of data at a time, I have opted to implement pagination. This allows users to navigate between pages ...

When the form is submitted, the text input vanishes and then the page is refreshed using AJAX technology

Can anyone help me troubleshoot why my page is reloading even though I used AJAX, and how to prevent it from clearing my input text after clicking the submit button? I tried using the show method to resolve this issue but it didn't work. <form met ...

Developers guide to using Selenium IDE

After downloading the source code of Selenium IDE, I'm eager to make some edits but unfortunately, I can't seem to find any documentation on how to do so. Hey folks, anyone aware of any resources available for developers working on Selenium IDE? ...

Troubleshooting Issue with JQuery Date Picker: Date Not Valid

Encountering an issue when using the date from JQuery DatePicker in an SQL Statement variable, resulting in an error of invalid datetime string. Even after attempting to format it with DateTime.Parse or Convert.DateTime. JQuery DatePicker <script> ...

Use jQuery to modify the default yellow color of Chrome's autofill feature

Struggling to get this code to work on my website, and it's starting to drive me crazy. I followed the instructions from BenjaminMiles' website, but something just isn't clicking. The jquery code snippet I'm using is: <script> ...

What causes the element to remain visible despite the changes made to the v-show attribute?

<!DOCTYPE html> <html> <head> <title>test</title> <script src="https://unpkg.com/vue"></script> </head> <body> <div id="app"> <p v-show="show&qu ...

Server becoming unresponsive following the cancellation of an AJAX call

In a specific scenario, my Ajax request to the server might take longer than usual (around 30-40 seconds). I am utilizing jQuery.ajax and specifying a timeout of 60 seconds. Consequently, if no response is received within this timeframe, the call gets canc ...

Issue with displaying hamburger menu items when using data-toggle in Angular

I've been diving into learning Angular and Bootstrap lately. I wanted to merge some existing HTML content into an Angular component, but ran into issues with its functionality. When I attempt to toggle the hamburger menu icon, nothing happens, and the ...

"Resolving the duplication issue of a textbox in Phonegap app

I encountered a strange issue recently. While trying to focus on the textbox in my PhoneGap application using touch, I noticed that there are actually 2 textboxes appearing. Please refer to the attached image: ...

The datatables button triggers an event twice

Whenever I click a button or tag in datatables, the modal opens twice and ajax runs twice. PS. I am using angular.js with datatables as a directive that is created by jQuery datatables, not the Angular datatables module. How can I solve this issue? Than ...

Cannot Display CSS Background Image Locally

Apologies for the simple inquiry, but I am facing an issue with displaying my background image using background-image:url() in the CSS. Strangely, it does not work with this method, but when I use content:url(); it works just fine. Interestingly, backgrou ...

Integrating HTML elements based on scroll movement

Is there a way to dynamically add a new Bootstrap row to my HTML code when scrolling the mouse downward using JavaScript? <div class="row"> <div class="col-md-6 col-xs-6" > <div> <img src="img/picture1.jpg" a ...

Using NodeJS to extract information from Opendata JSON files

I'm currently working on a project that involves fetching JSON data from an Open Dataset using NodeJS and passing it to angular. The challenge I'm facing is that I'm receiving a JSON file instead of a JSON object, which makes it difficult to ...