Is there a way to eliminate the lag time between hovering over this element and the start of the

https://jsfiddle.net/mrvyw1m3/

I am using CSS to clip a background GIF to text and encountering an issue. To ensure the GIF starts from the beginning on hover, I added a random string to the URL which causes a delay in displaying the GIF. During this delay, the text momentarily disappears before the GIF appears.

Is there a way to achieve this effect without the text disappearing before the GIF loads?

$(".navMenu2 li").mouseenter(function() {
  var n = Date.now();
  // or   var n = Math.random();
  $(this).css({
    background: "linear-gradient(transparent, transparent), url(https://media.giphy.com/media/l2QDSTa6UcsRRSM5a/giphy.gif?ver=" + n + ") center",
    webkitTextFillColor: 'transparent',
    webkitBackgroundClip: 'text'
  });
});

$(".navMenu2 li").mouseleave(function() {
  $(this).css({
    background: "",
    webkitTextFillColor: '',
    webkitBackgroundClip: ''
  });
});

Answer №1

To incorporate text masking, you will first need to create a static piece of text below that will remain unchanged, and then layer your link over it. Another option is to explore using ::before in conjunction with the same method. Achieving this effect can be done purely with CSS and :hover pseudo-class. Below is one approach:

Check out the JS Fiddle for a live demo: https://jsfiddle.net/snj91nkf/4/

<div class="navMenu2">
  <ul>
    <li class="liHver">
     <div class="link-cont">
        <a href="index.html"><span class="jap">作業</span><br>werk</a>
     </div>
     <div class="undertext">
       <span class="jap">作業</span><br>werk
     </div>
    </li> 
...

Customize the CSS as follows:

 .link-cont,
 .undertext{
   color: #0e0e0e;
   font-size: 10rem;
   font-weight: 600;
   list-style-type: none;
   transition: background-image 2s ease;
 }

 .navMenu2 li{
  position: relative;
 }

 .link-cont {
   position:absolute;
   top: 2;

 }

.link-cont a {
   text-decoration: none;
   color: #0e0e0e;
 }

Update the JavaScript with these changes:

 $(".link-cont").mouseenter(function() {
   var n = Date.now();
   // or   var n = Math.random();
   $(this).css({
     background: "linear-gradient(transparent, transparent), url(https://media.giphy.com/media/l2QDSTa6UcsRRSM5a/giphy.gif?ver=" + n + ") center",
     webkitTextFillColor: 'transparent',
     webkitBackgroundClip: 'text'
   });
 });

 $(".link-cont").mouseleave(function() {
   $(this).css({
     background: "",
     webkitTextFillColor: '',
     webkitBackgroundClip: ''
   });
});

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 issue of excessive recursion in Typescript

Currently, I am in the process of learning Typescript while working on some exercises. While attempting to solve a particular problem, I encountered an error related to excessive recursion. This issue arises even though I created wrapper functions. About ...

Tips for validating Enum Strings using the newest version of Joi?

Is there a way to validate Enum String? In the past, I followed this advice from: https://github.com/hapijs/joi/issues/1449 enum UserRole { Admin = 'admin', Staff = 'staff' } const validator = { create: Joi.object().keys({ ...

Using HTML classes to align text with colored letters in the center

I'm attempting to alter the colors of individual letters within a sentence using html and css. After conducting some research, I came across this method: Here is the html and css code snippet I used: .green { font-size: 20px; color: #0F3; te ...

The JQuery.ajax function encountered an unexpected identifier and threw an Uncaught SyntaxError

Hey there, I'm encountering this error and I'm stumped: jQuery.ajax Uncaught SyntaxError: Unexpected identifier I'm attempting to pass some customer information to another file named "pricealarm.php" in the main directory of the FTP-Serve ...

What is the best way to track and display the window.scrollY value in the console using Next.js

Unfortunately, my ScrollToTop component is not functioning correctly within my app. I have exhausted all possible debugging methods but am still unable to determine why the scrollY value is not being logged as expected. Even after moving the snippet to a ...

Top method for designing a "busy waiting" animation with customizable positioning using jQuery? (i.e., display it in the proximity of the activity)

I am planning to incorporate a busy waiting spinner on my website, following the method outlined in this post: How to show loading spinner in jQuery? - as it is considered the cleanest and simplest approach: $('#loadingDiv') .hide() / ...

Remove the background color from a semi-transparent circular CSS div when it is being dragged

My circular div is being dragged for a drag and drop operation, but there's always a translucent square around it. How can I remove this unwanted effect? body{ background : #BBD1DF; } .dragdemo { width: 170px; height: 170px; line-hei ...

The setState function in React.js fails to properly assign data

Recently, I've been using axios.get() to retrieve data from my database. The response is coming back correctly, but for some reason, when I attempt to update the state with this data, nothing seems to change. import React, { Component, useState, useE ...

Extracting data from a Razor page and passing it to an action method

I have an application that retrieves a list of records (applications) from a database and displays them on the screen. The records are loaded in a partial view (_ViewAllpartial.cshtml) and embedded in the Index.cshtml. Each record has a delete button, whic ...

Unique title: "Curved Blocks with Unusual Shapes in SVG Path

Hey there, I'm new to working with SVG and Highcharts. I found a jsfiddle online that I would like to customize for my project, but I've encountered an issue with the rounded corner blocks of lines in the Result panel. Here is the link to the js ...

Transport the unique identifier of the table row

After retrieving the list of followers from Instagram and storing it in an array in a session, I am displaying the data in a tabular format. <table class="tablesorter" cellspacing="0"> <thead> <tr> <th>&l ...

Discover the combobox element and its value can be easily achieved by using Selenium's find_element_by_xpath method

I am having trouble setting a value in a combobox using selenium. The find_element_by_xpath statement is failing to locate the combobox by class or ng-model. Specifically, I am attempting to change the time period for a stock from one day to one week. Her ...

What is the best way to pick an option from a dropdown menu using angularjs?

Is there a way to select an item from a dropdown list in AngularJS without using ng-repeat with an object array? I can easily select an option when using ng-repeat, but how can this be achieved with a normal select list? <select class="form-control" ...

Is it possible to develop a tagged template for a function that accepts parameters?

I came up with a special function that can act as a tagged literal: function generateStringFromTemplate(strings, ...keys) { // Object containing the values to interpolate return dict => { return keys.reduce( (acc, value, idx) => `${acc} ...

Using CSS Grid to Create Three Rows of Equal Height

I am facing an issue with my vertical menu that stretches 100% height. The rows inside this menu need to have equal height and be stretched to fit the container. Additionally, I noticed that adding a button seems to drop the container slightly below the pa ...

Developed a basic HTML form using PHP, however encountering issue where email is not being posted and instead opening a blank page

After creating HTML and PHP documents, I encountered an issue where upon submitting the form, I ended up with a blank page and didn't receive the expected email containing the form information. As someone relatively new to this, I would greatly apprec ...

Is your Ajax response suddenly failing to work after the initial attempt?

Describing my predicament: The code snippet below is what I have been using to insert a custom-designed div into my webpage. Initially, the div is successfully added; however, it stops working after the first instance. $('#addanother').click(fu ...

Troubleshooting ASP.NET Core 8 MVC: Issue with POST request from jQuery resulting in all null values in controller

When calling a controller endpoint from jQuery, all parameters are being received as null by the endpoint. jquery: $.ajax({ url: '/Test/SendEmailWithCode', type: "POST", async: false, contentType: "application/json ...

Steps to fix the moment-timezone import problem on meteor npm

I've been attempting to integrate the moment-timezone npm package into my meteor app without success. While the atmosphere package works smoothly, I prefer to use the npm package since the atmosphere one is no longer being updated. I have completely r ...

Is there a way to access a JavaScript object using Perl?

Looking to manipulate a JavaScript Object file with 5.5mb of longitude latitude data? Consider opening it in Perl for applying a detail-reducing algorithm that will generate a new object file with reduced dataset. My approach involves using a for loop to s ...