Hover over me to see the CSS animation translate upwards until it reaches a specific point

I am new to CSS animation and I am trying to create a circle that moves from one end to the other on hover. However, I am facing an issue where the circle goes off-screen when the browser size is changed. How can I make it stop at a certain point within the div? Is there a CSS solution for this or do I need to use Javascript or jQuery in this case?

html, body, #wrapper{
    min-width: 1000px;
    min-height: 100%;
    margin: 0;
    padding: 0;
    }

#wrapper{
    position: relative;
    }

body{
    padding: 50px;
    background-color: #f9f1dc;
    }

.one{
    background-color: #ffeffd;
    padding: 15px;
    border-radius: 50px;
    width: auto;
    }

.ball{
    display: inline-block;
    height: 100%;
    width: 100%;
    border-color: none;
    border-radius: 100%;
    background-color: #662a48;
    transition: transform 500ms ease-in-out; 
    }

.stay{
    height: 150px;
    width: 150px;
    border-radius: 150px;
    }

.stay:hover .ball{
    transform: translateX(770%);
    }
<!DOCTYPE html>
    <html>
    
        <head>
            <link href="css/ball-animation.css" rel="stylesheet" type="text/css">
        </head>
        
        <body>
            <div class="one">
                <div id="wrapper">
                    <div class="stay">
                        <div class="ball"></div>
                    </div>
                </div>
            </div>
        </body>
    
    </html>

Answer №1

Make sure to use vw units instead of "%" for animations. To fix the issue, adjust the width of the containers and the animation accordingly. You may need to experiment with different settings.

html, body, #wrapper{
    width:80vw;
    min-height: 100%;
    margin: 0;
    padding: 0;
}

#wrapper{
    position: relative;
}

body{
    padding: 50px;
    background-color: #f9f1dc;
}

.one{
    background-color: #ffeffd;
    padding: 15px;
    border-radius: 50px;
    width: auto;
}

.ball{
    display: inline-block;
    height: 100%;
    width: 100%;
    border-color: none;
    border-radius: 100%;
    background-color: #662a48;
    transition: transform 500ms ease-in-out; 
}

.stay{
    height: 150px;
    width: 150px;
    border-radius: 150px;
}

.stay:hover .ball{
    transform: translateX(50vw);
}
<!DOCTYPE html>
<html>

    <head>
        <link href="css/ball-animation.css" rel="stylesheet" type="text/css">
    </head>

    <body>
        <div class="one">
            <div id="wrapper">
                <div class="stay">
                    <div class="ball"></div>
                </div>
            </div>
        </div>
    </body>

</html>

Answer №2

Upon grasping the provided solutions, the ultimate outcome is as follows.

html, body, #wrapper{
  min-width: 1000px;
  min-height: 100%;
  margin: 0;
  padding: 0;
}

#wrapper{
  position: relative;
  height: 150px;
}

body{
  padding: 50px;
  background-color: #f9f1dc;
}

.one{
  background-color: #ffeffd;
  padding: 15px;
  border-radius: 50px;
  width: auto;
}

.ball {
  display: inline-block;
  height: 100%;
  width: 150px;
  border-color: none;
  border-radius: 100%;
  background-color: #662a48;
     position:absolute;
  left:0;
  transition: all 880ms ease-in-out; 
}

.stay {
  height:100%;
  width: 150px;
  border-radius: 150px;
 
}

.stay:hover .ball {
      left:100%;
      transform:translateX(-100%);
}
<!DOCTYPE html>
<html>

  <head>
    <link href="css/ball_anim.css" rel="stylesheet" type="text/css">
  </head>

  <body>
    <div class="one">
      <div id="wrapper">
        <div class="stay">
          <div class="ball"></div>
        </div>
      </div>
    </div>
  </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

What purpose does tagging serve in my template for polymer property binding?

I'm currently exploring the way Polymer handles the rendering of properties in a custom element's template. I've come across some interesting behavior that I haven't been able to fully grasp yet. Specifically, I noticed that certain pro ...

Position the SVG next to the link text in a Bootstrap navbar brand

I am using the .navbar-brand class from Bootstrap to include an SVG in my navbar. However, I want to display text next to the SVG and align it properly. The SVG and text are currently in the navbar but they are not aligned correctly. Below is the code snip ...

Tips for making a bookmark for your iframe content

Within this HTML code, there is a list element with the ID "about_ma" and an iframe named "page" that is initially hidden. <div id="navigation"> <ul id="nav"> <li id="about_ma"><a href="index1.php?name=about.php">Ab ...

Achieve the appearance of table-like alignment without the need for traditional tables

Any ideas on how to achieve the following layout: <table border="0"> <tbody> <tr> <td style="margin-right:5px;"> <h2 id="optiona" class="option optiona optiona2">a. aa </h2> </td> ...

Slideshow Display Suddenly Halts at the Last Image

I am currently working on a Bootstrap JS Carousel that showcases several images stored in the project folder. Each image's filepath is retrieved from an SQL Server database and displayed within the carousel. While the images are displaying correctly ...

Tips on customizing image borders/masks with hover effects

Is there a React library or a simple CSS trick to create an image's canvas cropping effect on hover? For example, similar to this: Thanks in advance! ...

Tips for customizing the CSS of a child component that has been imported from a different module in Angular 2

I have been using agm-snazzy-window from amg-snazzy-window There is a mention that I can modify the css class, but when I try to do so, it doesn't seem to work. Here is an example: map-component.html <agm-snazzy-info-window [closeWhenOthersOp ...

Is there a way to get an iframe to mimic the behavior of other media elements within a horizontal scrolling container?

Take a look at this code snippet: $(document).ready(function() { $('.scrollable-area').on('wheel', function(e) { var scrollLeft = $(this).scrollLeft(); var width = $(this).get(0).scrollWidth - $(this).width(); var delta ...

Tips for presenting HTML source code with appropriate tag coloring, style, and indentation similar to that found in editors

I need to display the source code of an HTML file that is rendered in an iframe. The source code should be shown with proper tag colors and indentations similar to editors like Sublime Text. https://i.stack.imgur.com/IbHr0.png I managed to extract the sour ...

What is the best way to dynamically call a different PHP file each day for an entire year?

As a PHP novice, my goal is to integrate a daily meditation feature that corresponds to the current day. For example, on January 1st, I would like to display content from 1_1.php, and on the following days, it should load 1_2.php, 1_3.php, continuing unti ...

Creating word spacing in CSS paired with a navigation menu using Dreamweaver

As a beginner in Dreamweaver, CSS, and HTML, I may have made some mistakes or overlooked simple solutions. I am currently struggling with how to separate words in my navigation menu, as they always appear centered. Despite trying adjustments like "word-spa ...

Separate the selected option in the TEXTAREA by commas to make it easier to

Can you assist me with integrating this example? I have the following elements: When adding a textarea, I require an option to be selected and separated by a comma. For instance: Here I will select an option: Subsequently, this chosen option must be ad ...

Finding a specific section on a webpage using AngularJS

Is it possible to create in-page navigation to a specific section within an Angular application without triggering the routing service? For example: The section we want to jump to: <a name="tips"> <div>Tips and tricks...</div> < ...

Adjusting the appearance of internal components with material-ui icons

Currently working on a project using react and material-ui where I am looking to customize the styles of specific elements within components. An example is the ListItem component which includes primaryText, leftIcon among others, and my goal is to modify t ...

Fiddle demonstrates HTML functionality, while local testing is unsuccessful

Currently, I am in the process of creating an image slider and attempting to run it on my personal computer. However, upon doing so, I have encountered a problem where the page is not rendering correctly. Additionally, I receive an ActiveX warning message ...

Scale up each image with the use of Java script

I have a main container with three different sub-containers, each containing an image and text. I want to achieve the effect of zooming in on the image of the specific sub-container when hovering over it. Currently, when I hover over any sub-container, all ...

Tips for adjusting the width of table columns when dealing with browser fields

When working with a table field, I am allowing input as a file. <table> <tr> <th> <input type="file" name="icon" id="icon" /> </th> </tr> </table> The file input field is recommended to have a width of 242-246px ...

Confirm that the input into the text box consists of three-digit numbers separated by commas

Customers keep entering 5 digit zip codes instead of 3 digit area codes in the telephone area code textbox on my registration form. I need a jQuery or JavaScript function to validate that the entry is in ###,###,###,### format without any limit. Any sugge ...

What steps can be taken to convert this function into a more concise, dry function?

I'm attempting to customize a typewriter effect on my webpage, and while it successfully displays predefined data, I am struggling with converting it into a function that can receive values and then display those values. I have made attempts to modif ...

What is the best way to display a Bootstrap toggle?

I am facing an issue with a Bootstrap toggle in a Handlebars template. When the page initially loads, the toggle is visible, however, after re-templating the Handlebars template that contains the toggle, it disappears. Before Re-Template: Initial code : ...