Interactive Text Transformation on Mouse Over

My goal is to create a sleek and clean Index page featuring a simple white background with text centered in the middle. The initial text will be:

                               USEStudio

Upon hovering the mouse, the text will transform into:

                         UrbanSpaceEvent.Studio

Additionally, I want to make sure that the second text is clickable and directly leads to the website.

Despite experimenting with various CSS codes, I have struggled to incorporate fade-in/fade-out effects and properly link the text to the site.

Answer №1

How to easily change visibility

Using CSS only

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>example.com</title>
    <style>
        .wrap{
            text-align: center;
        }
        .wrap:hover .state--off {
            display: block;
        }
        .wrap:hover .state--on,
        .state--off {
            display: none;
        }
    </style>
</head>
<body>
    <a href="YourLinkGoesHere" class="wrap">
        <p class="state--on">ExampleStudio</p>
        <p class="state--off">NewSpaceStudio</p>
    </a>

Adding fade effects using jQuery

A quick and simple way

(function($) {
  var toggleVisibility = function( domWrap, sClass ) {
    $Children = $( domWrap ).children();
    var $Hidden  = $Children.filter(':hidden'),
        $Visible = $Children.filter(':visible');
    $.when(
      $Visible.animate({opacity: 0})
    ).then(function(){
      $Visible.hide();
      $Hidden
        .css({display: 'block', opacity: 0})
        .animate({opacity: 1}, 'slow');
    })
  };
  $(function() { // document ready
    $('.wrap')
      .mouseenter(function(){ toggleVisibility( this ) })
      .mouseleave(function(){ toggleVisibility( this ) })
  })
})(jQuery)
.wrap{
    text-align: center;
}

.state--off {
    display: none;
}
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>example.com</title>
</head>
<body>
    <a href="YourLinkGoesHere" class="wrap">
        <p class="state--on">ExampleStudio</p>
        <p class="state--off">NewSpaceStudio</p>
    </a>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

Alternatively, you can use a library like:

Animate.css for CSS animations

Utilizing CSS animation with jQuery fallback

(function($) {

    // choose from https://daneden.github.io/animate.css/ and customize this script
    var sClassIn  = 'zoomIn',    // <- your string here //////////////////
        sClassOut = 'rotateOut'; // <- your string here //////////////////

    sClassIn  += ' animated';
    sClassOut += ' animated';

    var sAnimationEnd = (function() {
        var t,
            el = document.createElement('fakeelement'),
            animations = {
                'animation': 'animationend',
                'OAnimation': 'oAnimationEnd',
                'MozAnimation': 'animationend',
                'WebkitAnimation': 'webkitAnimationEnd'
            }

        for (t in animations) {
            if (el.style[t] !== undefined) {
                return animations[t];
            }
        }
    })();

    var toggleVisibility = function(domWrap, sClass) {
        $Children = $(domWrap).children();
        var $Hidden = $Children.filter(':hidden'),
            $Visible = $Children.filter(':visible');

        if (sAnimationEnd) { // modern browsers css animation
            var $Deferred = $.Deferred();
            $Visible.attr('class', sClassOut).one(
                sAnimationEnd,
                function() {
                    $Visible.hide().attr('class', '');
                    $Hidden.show().attr('class', sClassIn);
                    $Deferred.resolve();
                }
            );
            return $Deferred.promise();
        } else { // fallback | js animation
            return $.when( $Visible.animate({ opacity: 0 }) ).then(function() {
                $Visible.hide();
                $Hidden.show().animate({ opacity: 1 }, 'slow');
            });
        }

    };

    $(function() { // document ready
        $('.wrap')
            .mouseenter(function() { toggleVisibility(this) })
            .mouseleave(function() { toggleVisibility(this) })
    })

})(jQuery)
.body, html {
    overflow: hidden;
}
.wrap{
    text-align: center;
}
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>stackoverflow.com</title>
    <style></style>
    <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8feee1e6e2eefbeaa1ecfcfccfbca1baa1bd">[email protected]</a>/animate.css" rel="stylesheet"/>
</head>
<body>
    <a href="YourLinkGoesHere" class="wrap">
        <p>ExampleStudio</p>
        <p style="display:none">NewSpaceStudio</p>
    </a>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

Answer №2

Here is a way to achieve the desired result using only CSS and no JavaScript:

<html>
<head>
<title></title>
<style type="text/css>
.hover_text:after {
    content: attr(data-nothovertext);
}
.hover_text:hover:after {
    content: attr(data-hovertext);
}
.hover_text {
    text-align: center;
        display:block;
}
</style>
</head>
<body>

<a href="#link_to_your_url" class="hover_text" data-hovertext="UrbanSpaceEvent.Studio" data-nothovertext="USEStudio" ></a>

</body>
</html>

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

Concatenating strings with JavaScript

I am currently working on building a web page using a combination of html and javascript. I have a json file that provides inputs for some specific content I need to display. My main goal is to set up an address variable in order to show the Google Maps AP ...

A single Modal, Ajax, and data that is continuously refreshed

I'm currently facing a challenge in my project as I try to implement Ajax functionality. Although I'm relatively new to using it, I believe I have a basic understanding of its workings. My website involves collecting form data, posting it to a d ...

In what time frame is Javascript/AJAX functioning?

Do you know if the times are measured in milliseconds or seconds? I'm puzzled why these two scripts aren't synchronizing - there's a significant delay. $(document).ready(function() { $("#idle").delay(300000).fadeIn(500); }); var interv ...

Preventing box shadows from blending together

I'm struggling with a design issue on my site where I have four divs in the center, each represented by a box with a box-shadow. Unfortunately, the colors of the shadows are getting mixed up and creating an unwanted effect. Below is the CSS code used ...

Line breaks showing up on the page that are not present in the HTML source code

Why are unwanted line breaks appearing in my rendered DOM that are not in the source code, causing the content to be displaced? And how can I resolve this issue? Below is the code snippet: <div class="float-left" style="position:relative;left:15px"> ...

Utilizing Angular's Dependency Injection in Component Development

Can component injection be achieved in AngularJS using dependency injection? There is a SignalR hub factory that I want to use for injecting my SignalR hub proxy. Below is the code snippet where I am creating an ngTable Component that needs to be updated ...

Extracting props data from a component in React.js - a step-by-step guide

I am currently developing a react.js application with react-select. I have created a dropdown menu and when an item is clicked, I need to pass that item to a function that is connected to the redux store. How can I retrieve data from a component used in re ...

What could be causing my view to not load the jQuery code from _Layout.cshtml, yet it works when I include it directly in the view file?

Why is the jQuery inherited from Layout.cshtml not loading in my view? When I use a local link to jQuery in the view, it works fine. Otherwise, it doesn't. _Layout.cshtml: <!DOCTYPE html> <html> <head> <meta charset="utf-8" ...

Retrieve the $http data from a function that is external to it

Apologies if the title is confusing, it's hard to explain in a different way. The situation I have is... app.controller('viewProductController', ['$scope', 'dataFactory', '$routeParams', function($scope, dat ...

When going through an array using jquery, only the final object is returned

I am diving into the world of jQuery and dealing with what seems to be a basic issue. <input type="text" name="text1" value=""></input> <input type="text" name="text2" value=""></input> <input type="text" name="text3" value=""&g ...

If the text width of a label exceeds the total width of its container, intelligently display a sub-string based on pixel calculations

I am looking to shorten the text inside a label if its width exceeds the total width of its container. Instead of displaying the full text, I want to display a sub-string of it. if (SensorType.Text.Length >= 25) { SensorType.Text = SensorType.Text ...

The tooltip of the Material UI IconButton is displaying incorrectly

Within my ReactJS application, I am utilizing Material UI along with react-bootstrap-table components. One particular cell in my application utilizes the Material UI IconButton as shown below: <IconButton tooltip={t('tooltips:editRegulation&apos ...

Techniques to dynamically insert database entries into my table using ajax

After acquiring the necessary information, I find myself faced with an empty table named categorytable. In order for the code below to function properly, I need to populate records in categoryList. What should I include in categoryList to retrieve data fro ...

The hover effect for changing the style of one element when hovering over another element is not functioning as

I've encountered an issue with styling a triangle element using the .something:hover .another{...} selector. Can anyone help me understand what might be causing this problem? .actions { display: flex; margin-top: 20px; max-width: 260px; } .a ...

Populating a clickable list and form with a complex JavaScript object

I have a code snippet that takes an unstructured String and parses it into a JavaScript object. My next step is to integrate it into a web form. You can check out the demo here. The demo displays the structured object hierarchy and showcases an example of ...

Choosing between setting a height of 100vh versus a minimum height of 100vh

In the development of my app, I noticed an interesting issue. When I set the background on the html with a height of 100vh and resize the viewport to cause vertical overflow, the background does not cover the overflowed content: html { height ...

Issue with AJAX loading functionality not functioning properly in Internet Explorer

For a project, I have a portfolio that I need to create. The front page consists of a div with a loader which determines the screen size upon landing and selects the content to be pulled in using ajax. The reason for this approach is due to the simplicity ...

"Incorporating a datepicker into input fields that are added dynamically

`: I acquired a code from the internet that allows me to dynamically add and remove input fields and a dropdown list. In my `index.php` file, I select an account name from the dropdown list (`$row["name"]`) and retrieve the corresponding account ID (`$row[ ...

Enabling and disabling HTML image input based on checkbox selection

I have utilized the code below to toggle the status of the image button between enabled and disabled modes using JQuery. Here is the code for a checkbox in Yii format: <?php echo CHtml::CheckBox('TermsAgreement','', array ('ch ...

Is there a way to ensure the collapsible item stays in its position?

I'm encountering an issue with the display of items within collapsible cards. Here is what it currently looks like: And this is how I want it to appear: Is there a way to achieve the desired layout using Bootstrap's Grid or Flex Layout? Here i ...