CSS text width going from left to right

I am attempting to create a text fade effect from left to right, inspired by the technique discussed in this answer. However, I would like the text to be concealed behind a transparent background div instead of the white background used in the example. Is this achievable with CSS? My rationale is that there will be an image behind the text that I want to gradually reveal.

Answer №1

If you want to create a simple animation, just adjust the width property from 0 to 100% in the @keyframes rule (similar to the example provided in your question) to reveal different parts of the text.

Here's a quick demo for you to see it in action. Click on Zero:

stripe.onclick = function() {
  var sec = new Date().getSeconds() % 10;
  stripe.classList.add('animate');
  digit.classList.add('animate');
  console.log();
};
#digit {
  width: 20px;
  overflow: hidden;
  font: 32px "Courier New", monospace;
  cursor: pointer;
  transition: 2s linear width;
}

#stripe {
  width: 20px;
  transition: 2s linear width;
}

#stripe.animate {
  width: 200px;
  transition: 2s linear width;
}

#digit.animate {
  width: 200px;
  transition: 2s linear width;
}
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8>
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Title</title>
  <style>
  </style>
</head>
<body>

  <div id="digit"><span id="stripe">0123456789</span></div>

<script>
</script>
</body>
</html>

P.S.

This JavaScript code is just for testing purposes. You can achieve the same effect using only @keyframes.

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

Preventing jQuery plugin from overriding default settings

I have created a jQuery plugin using the nested namespace pattern, inspired by the design template found in Addy Osmani's book. The plugin is a simple gallery and everything seems to be functioning correctly. However, I am facing an issue when attemp ...

Make the inner div within the td stretch to cover the entire height of the td

Inside the first tds, there is dynamic text content that automatically expands the trs and tds. However, the second tds have a div with a background image but no text inside. I want these divs with background images to expand or collapse along with the tab ...

unable to receive input value

<script type="text/javascript" language="javascript"> $(function() { $("#distributor").autocomplete({ source: function(request, response) { $.ajax({ url: "/Devices/autoDistributor", ...

Tips for extracting information from a JSON file using $routeParams in AngularJS

https://i.stack.imgur.com/NQCpy.png I am currently encountering an issue with retrieving data using $routeparams. Here is a description of my problem: Retrieving the URL to redirect console.log($routeParams); console.log($routeParams.json_url); $.getJS ...

Create a custom jQuery plugin that enables users to toggle checkboxes with the click of a button

Having trouble with my jQuery button code that is supposed to toggle associated checkboxes but ends up freezing the browser. I am in need of the following functionalities: 1) Clicking on "select all" should select all checkboxes. 2) Clicking on "select all ...

What is causing my DropDown List filter to reset when using Pagination?

I am currently working in ASP.NET MVC and I have set up a system to display data from my database on the screen. The interface includes a dropdown list at the top of the page which allows users to filter the data based on two options (option 1 and option 2 ...

Utilize AJAX to fetch and display the response from a Node JS route directly onto an HTML page

At the moment, I am retrieving client-side HTML/JS inputs (var1 and var2) which are then sent to server-side Node JS. The input values are stored in variables through an AJAX post call made to a specific route. What I want now is to define the values of v ...

What is the best way to input an HTML element into AngularJS code?

I am looking to integrate the html element into my angularjs code. Within my HTML, I have elements such as data-form-selector='#linechart_general_form' and data-url="{% url 'horizon:admin:metering:samples'%}" that I need to access withi ...

Generating a JSON data set with two separate pieces of data, not contained within a dictionary

Within my application, there exists an HTML table that is dynamically generated using the following code: function generateTableRow() { var emptyColumn = document.createElement('tr'); emptyColumn.className ='data'; emptyColumn.inne ...

When viewing Google maps in full screen mode, the image suddenly vanishes

I have a map with a logo positioned in the lower right corner near the controls. However, when I switch to full screen mode, the logo disappears. I can see the div (aggdata-info) in Firebug, but the image/logo is not visible. Any suggestions on how to fix ...

Issue with CSS transition bug in Offcanvas on Android version 4.1.x

I am attempting to develop an offcanvas menu similar to the one featured in the Google Plus app. Currently, my code functions properly on most devices (android/ios) and browsers (ff, chrome, IE8+). The only issue I am encountering is on a Samsung Galaxy ...

Troubleshooting: Css navbar alignment

How can I center the navigation bar both horizontally and vertically? I've tried various methods but nothing seems to work. Here is my HTML: <section class="navigation" ng-controller="NavController"> <div class="nav-container"> ...

Ways to showcase INPUT TYPE when making a Selection?

I've been struggling with a simple issue and despite trying multiple solutions, I can't seem to get it right. I have a form where I'm using the <select> tag with two options: coo and uh. What I want is for an additional input type fiel ...

Acquiring the index of a selector event within a list of dynamic elements

I am seeking guidance on how to go about solving the issue of obtaining an event index. I have a hunch that closures might play a role in the solution and would appreciate some insights. Initially, I dynamically build an HTML5 video container using an aja ...

Ways to initiate a flip motion

Looking for a way to create a flip image effect when clicked by the user. Here is the code I have so far: let img = document.querySelector('img') let div; let click = 0; img.onclick=function(){ console.log(click) if(click %2 ==0){ d ...

Updating the logo image on mobile devices using responsive CSS styling

My goal is to show a different image to users on mobile devices using only CSS, as I am unable to access the HTML code. On mobile, I used display:none for the header-logo-image img { and then added a background-url to the div to successfully display my alt ...

Ways to retrieve the content of a text box within a cell

Here is the code snippet I am currently working with: <tr val='question'> <td> <input style='width: 500px' type='text' placeholder='Q.Enter your question here for radio button? '> </ ...

WP Ajax failing to work in the else statement

I am currently developing a WordPress plugin that includes a special feature. This feature involves a checkbox that, when checked by a user, saves a specific value in the database using ajax. Conversely, when the checkbox is unchecked, the value should be ...

Trouble encountered while refreshing a <div> element using AJAX functionality

My web page is being dynamically generated by scriptA.php. Every 5 minutes, the content of the #WatchContainer div element needs to be updated. This content is created by scriptB.php. I have included scriptB.php in scriptA.php using "include" and a variabl ...

Using jQuery, you can enclose a string of text with HTML tags easily

This specific content within the span is being dynamically created by PHP. However, I am uncertain how to efficiently target the text string in order to begin using jQuery. <!-- input: --> <span class="price">RM1,088.00 Annually + RM10.00 Se ...