Can't proprely align text with animation in HTML

回眸只為那壹抹淺笑 提交于 2021-02-11 14:31:13

问题


I am trying to align a text to be centered with the page (as you can see here https://imgur.com/oxokwqx the "Carol Housing" text is a bit to the left . The problem is that my text has a javascript animation added to it and even if try to center it with FlexBox or text-align dosen't seem to do much Here is the code

HTML CODE

/*Animatie titlu linii frumoase*/

anime.timeline({loop: false})
  .add({
    targets: '.ml5 .line',
    opacity: [0.5,1],
    scaleX: [0, 1],
    easing: "easeInOutExpo",
    duration: 1000
  }).add({
    targets: '.ml5 .line',
    duration: 1000,
    easing: "easeOutExpo",
    translateY: (_el, i) => (-0.625 + 0.625*2*i) + "em"
  })
   .add({
    targets: '.ml5 .letters-left',
    opacity: [0,1],
    translateX: ["0.5em", 0],
    easing: "easeOutExpo",
    duration: 600,
    offset: '-=300'
  }).add({
    targets: '.ml5 .letters-right',
    opacity: [0,1],
    translateX: ["-0.5em", 0],
    easing: "easeOutExpo",
    duration: 600,
    offset: '-=600'
  }).add({
    targets: '.ml5',
     duration: 1000,
    easing: "easeOutExpo",
    delay: 1000 ,
  });
 

/*Animatie text*/

  var textWrapper = document.querySelector('.ml16');
textWrapper.innerHTML = textWrapper.textContent.replace(/\S/g, "<span class='letter'>$&</span>");

anime.timeline({loop: true})
  .add({
    targets: '.ml16 .letter',
    translateY: [-100,0],
    easing: "easeOutExpo",
    duration: 1400,
    delay: (_el, i) => 30 * i
  }).add({
    targets: '.ml16',
    opacity: 0,
    duration: 1000,
    easing: "easeOutExpo",
    delay: Infinity
  });
  
  var textWrapper = document.querySelector('.ml17');
  textWrapper.innerHTML = textWrapper.textContent.replace(/\S/g, "<span class='letter'>$&</span>");
  
  anime.timeline({loop: true})
    .add({
      targets: '.ml17 .letter',
      translateY: [-100,0],
      easing: "easeOutExpo",
      duration: 1400,
      delay: (_el, i) => 30 * i
    }).add({
      targets: '.ml17',
      opacity: 0,
      duration: 1000,
      easing: "easeOutExpo",
      delay: Infinity
    });
    
    var textWrapper = document.querySelector('.ml18');
    textWrapper.innerHTML = textWrapper.textContent.replace(/\S/g, "<span class='letter'>$&</span>");
    
    anime.timeline({loop: true})
      .add({
        targets: '.ml18 .letter',
        translateY: [-100,0],
        easing: "easeOutExpo",
        duration: 1400,
        delay: (_el, i) => 30 * i
      }).add({
        targets: '.ml18',
        opacity: 0,
        duration: 1000,
        easing: "easeOutExpo",
        delay: Infinity
      });
      
      var textWrapper = document.querySelector('.ml19');
    textWrapper.innerHTML = textWrapper.textContent.replace(/\S/g, "<span class='letter'>$&</span>");
    
    anime.timeline({loop: true})
      .add({
        targets: '.ml19 .letter',
        translateY: [-100,0],
        easing: "easeOutExpo",
        duration: 1400,
        delay: (_el, i) => 30 * i
      }).add({
        targets: '.ml19',
        opacity: 0,
        duration: 1000,
        easing: "easeOutExpo",
        delay: Infinity
      });
      

      var slideIndex = 0;
      showSlides();
      
      function showSlides() {
        var i;
        var slides = document.getElementsByClassName("mySlides");
        var dots = document.getElementsByClassName("dot");
        for (i = 0; i < slides.length; i++) {
          slides[i].style.display = "none";  
        }
        slideIndex++;
        if (slideIndex > slides.length) {slideIndex = 1}    
        for (i = 0; i < dots.length; i++) {
          dots[i].className = dots[i].className.replace(" active", "");
        }
        slides[slideIndex-1].style.display = "block";  
        dots[slideIndex-1].className += " active";
        setTimeout(showSlides, 4000); // Change image every 2 seconds
      }
      
@import url('https://fonts.googleapis.com/css2?family=Lato:wght@300&display=swap');
@import url(font-awesome.min.css);
@import url("https://fonts.googleapis.com/css?family=Poppins:300,400,500,600,700");


:root {
  --primary-color: #047aed;
  --secondary-color: #1c3fa8;
  --dark-color: #002240;
  --light-color: #f4f4f4;
  --success-color: #5cb85c;
  --error-color: #d9534f;
}

* {
  box-sizing: border-box;
  padding: 0;
  margin: 0;
}
.mySlides {
  display: none;
}

body {
  font-family: 'Lato', sans-serif;
  color: #333;
  line-height: 1.6;
}

ul {
  list-style-type: none;
}

a {
  text-decoration: none;
  color: #333;
}

h1,
h2 {
  font-weight: 300;
  line-height: 1.2;
  margin: 10px 0;
}

p {
  margin: 10px 0;
}

img {
  width: 100%;
vertical-align: middle;
  
}

code,
pre {
  background: #333;
  color: #fff;
  padding: 10px;
}

.hidden {
  visibility: hidden;
  height: 0;
}


/* Features */
.features-head img,
.docs-head img {
  width: 200px;
  justify-self: flex-end;
}

.features-sub-head img {
  width: 300px;
  justify-self: flex-end;
}

.features-main .card > i {
  margin-right: 20px;
}

.features-main .grid {
  padding: 30px;
}

.features-main .grid > *:first-child {
  grid-column: 1 / span 3;
}

.features-main .grid > *:nth-child(2) {
  grid-column: 1 / span 2;
}

/* Docs */
.docs-main h3 {
  margin: 20px 0;
}

.docs-main .grid {
  grid-template-columns: 1fr 2fr;
  align-items: flex-start;
}

.docs-main nav li {
  font-size: 17px;
  padding-bottom: 5px;
  margin-bottom: 5px;
  border-bottom: 1px #ccc solid;
}

.docs-main a:hover {
  font-weight: bold;
}


/* Tablets and under */
@media (max-width: 768px) {
  .grid,
  .showcase .grid,
  .stats .grid,
  .cli .grid,
  .cloud .grid,
  .features-main .grid,
  .docs-main .grid {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
  }

  .showcase {
    height: auto;
  }

  .showcase-text {
    text-align: center;
    margin-top: 40px;
    animation: slideInFromTop 1s ease-in;
  }

  .showcase-form {
    justify-self: center;
    margin: auto;
    animation: slideInFromBottom 1s ease-in;
  }

  .cli .grid > *:first-child {
    grid-column: 1;
    grid-row: 1;
  }

  .features-head,
  .features-sub-head,
  .docs-head {
    text-align: center;
  }

  .features-head img,
  .features-sub-head img,
  .docs-head img {
    justify-self: center;
  }

  .features-main .grid > *:first-child,
  .features-main .grid > *:nth-child(2) {
    grid-column: 1;
  }
}

/* Mobile */
@media (max-width: 500px) {
  .navbar {
    height: 120px;
  }

  .navbar .flex {
    flex-direction: column;
    
  }

  .navbar ul {
    padding: 10px;
    background-color: rgba(0, 0, 0, 0.1);
  }
  
  .showcase-form {
    width: 300px;
  }
}
.container {
  max-width: auto;
  margin: 0 auto;
  overflow: auto;
  padding: 0 40px;
  align-self: start;
  
}
.main {
  min-height: 100vh; 
  height:auto ;
}

.card {
  background-color: #fff;
  color: #333;
  border-radius: 10px;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2);
  padding: 20px;
  margin: 10px;
}

.btn {
  display: inline-block;
  padding: 10px 30px;
  cursor: pointer;
  background: var(--primary-color);
  color: #fff;
  border: none;
  border-radius: 5px;
}

.btn-outline {
  background-color: transparent;
  border: 1px #fff solid;
}

.btn:hover {
  transform: scale(0.98);
}

/* Backgrounds & colored buttons */
.bg-primary,
.btn-primary {
  background-color: var(--primary-color);
  color: #fff;
}

.bg-secondary,
.btn-secondary {
  background-color: var(--secondary-color);
  color: #fff;
}

.bg-dark,
.btn-dark {
  background-color: var(--dark-color);
  color: #fff;
}

.bg-light,
.btn-light {
  background-color: var(--light-color);
  color: #333;
}

.bg-primary a,
.btn-primary a,
.bg-secondary a,
.btn-secondary a,
.bg-dark a,
.btn-dark a {
  color: #fff;
}

/* Text colors */
.text-primary {
  color: var(--primary-color);
}

.text-secondary {
  color: var(--secondary-color);
}

.text-dark {
  color: var(--dark-color);
}

.text-light {
  color: var(--light-color);
}

/* Text sizes */
.lead {
  font-size: 20px;
}

.sm {
  font-size: 1rem;
}

.md {
  font-size: 2rem;
}

.lg {
  font-size: 3rem;
}

.xl {
  font-size: 4rem;
}

.text-center {
  text-align: center;
}

/* Alert */
.alert {
  background-color: var(--light-color);
  padding: 10px 20px;
  font-weight: bold;
  margin: 15px 0;
}

.alert i {
  margin-right: 10px;
}

.alert-success {
  background-color: var(--success-color);
  color: #fff;
}

.alert-error {
  background-color: var(--error-color);
  color: #fff;
}

.flex {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: row;
  height: 100%;
}

.flex-basis-3{
  flex-basis: 33%
}

.text-center{
  text-align: center
}

.text-right{
  text-align: right
}
.align-better{
  display: flex; 
  justify-content: flex-end;
}
.no-list{
  list-style: none;
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
  justify-content: center;
  align-items: center;
  height: 100%;
}

.grid-3 {
  grid-template-columns: repeat(3, 1fr);
}
.sticky{
  
    position: fixed;
    top: 0;
    width: 100%;
  }


/* Margin */
.my-0{
  margin : 0rem 0;
}
.my-1 {
  margin: 1rem 0;
}

.my-2 {
  margin: 1.5rem 0;
}

.my-3 {
  margin: 2rem 0;
}

.my-4 {
  margin: 3rem 0;
}

.my-5 {
  margin: 4rem 0;
}

.m-1 {
  margin: 1rem;
}

.m-2 {
  margin: 1.5rem;
}

.m-3 {
  margin: 2rem;
}

.m-4 {
  margin: 3rem;
}

.m-5 {
  margin: 4rem;
}

/* Padding */
.py-1 {
  padding: 1rem 0;
}

.py-2 {
  padding: 1.5rem 0;
}

.py-3 {
  padding: 2rem 0;
}

.py-4 {
  padding: 3rem 0;
}

.py-5 {
  padding: 4rem 0;
}

.p-1 {
  padding: 1rem;
}

.p-2 {
  padding: 1.5rem;
}

.p-3 {
  padding: 2rem;
}

.p-4 {
  padding: 3rem;
}

.p-5 {
  padding: 4rem;
}
/*Bara de sus*/
.navbar {
  
    z-index: 9999;
    height: 100px;
    position: sticky; 
    top: 0; 
  }
  .navbar ul {
    display: flex;
    flex-direction: row;
    flex-grow:1;
  }
  
  .navbar a {
    
    padding: 10px;
    margin: 0 2px;
  }
  
  
  .navbar a:hover {
    border-bottom: 2px #fff solid;
  }
  
  .navbar .flex {
    justify-content:space-between;
  }
  .navbar .social a{
  
    margin: 0 2px;
    flex-grow:1;
    font-size: 18px;
  }
  .navbar .social > *:nth-child(3){
    font-size: 20px;
    
  }
  
  
  .ml5 .text-wrapper {
    position: relative;
    display: inline-block;
    padding-top: 0.1em;
    padding-right: 0.05em;
    padding-bottom: 0.15em;
    line-height: 1em;
  }
  
  .ml5 .line {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    margin: auto;
    height: 3px;
    width: 100%;
    background-color: #fff;
    transform-origin: 0.5 0;
  }
  
  
  .ml5 .letters {
    display: inline-block;
    flex-direction: row;
    opacity: 0;
  }
  .ml16 {
    color: #fff;
    font-weight: 800;
    text-transform: uppercase;
    text-align: center;
    overflow: hidden;
  }
  
  .ml16 .letter {
    display: flex;
    line-height: 1em;
    flex-direction: row;
  }
  
  .ml17 {
    color: #fff;
    font-weight: 800;
    text-transform: uppercase;
    text-align: center;
    overflow: hidden;
    
  }
  
  .ml17 .letter {
    display: flex;
    line-height: 1em;
    flex-direction: row;
  }
  .ml18 {
    color: #fff;
    font-weight: 800;
    text-transform: uppercase;
    text-align: center;
    overflow: hidden;
    
  }
  
  .ml18 .letter {
    display: flex;
    line-height: 1em;
    flex-direction: row;
  }
  .ml19 {
    color: #fff;
    font-weight: 800;
    text-transform: uppercase;
    text-align: center;
    overflow: hidden;
    
  }
  
  .ml19 .letter {
    display: flex;
    line-height: 1em;
    flex-direction: row;
  }

  /*Imagini slideshow*/

  .slideshow-container {
    max-width: auto;
    position: relative;
    margin: auto;
  }

  /* The dots/bullets/indicators */
  .dot {
    height: 15px;
    width: 15px;
    margin: 0px 2px;
    padding: 5px 20px;
    bottom:35px;
    position: relative;
    border-radius: 16%;
    background-color: var(--dark-color);
    
    display: inline-block;
    transition: background-color 0.6s ease;
  }
  
  .active {
    background-color: #fff;
  }
  
  /* Fading animation */
  .fade {
    -webkit-animation-name: fade;
    -webkit-animation-duration: 1.5s;
    animation-name: fade;
    animation-duration: 1.5s;
  }
  
 
  
  /* On smaller screens, decrease text size */
  @media only screen and (max-width: 300px) {
    .text {font-size: 11px}
  }

  /*Footer*/
  .footer {
    z-index: 9999;
    min-height: 80px; 
    top: 0; 
  }
  .footer  a{
    
    margin: 0 5px;
    }
  
  .direction-row{
    flex-direction: row;
  }
  
  .footer a:hover {
    border-bottom: 2px #fff solid;
  }
  

  /* CLItoris*/
  .cli .grid {
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(2, 1fr);
  }
  
  .cli .grid > *:first-child {
    grid-column: 1 / span 2;
    grid-row: 1 / span 2;
  }

  /*Animatii doar CSS*/
  @keyframes slideInFromLeft {
    0% {
      transform: translateX(-100%);
    }
  
    100% {
      transform: translateX(0);
    }
  }
  
  @keyframes slideInFromRight {
    0% {
      transform: translateX(100%);
    }
  
    100% {
      transform: translateX(0);
    }
  }
  
  @keyframes slideInFromTop {
    0% {
      transform: translateY(-100%);
    }
  
    100% {
      transform: translateX(0);
    }
  }
  
  @keyframes slideInFromBottom {
    0% {
      transform: translateY(100%);
    }
  
    100% {
      transform: translateX(0);
    }
  }
 
  @-webkit-keyframes fade {
    from {opacity: .4} 
    to {opacity: 1}
  }
  
  @keyframes fade {
    from {opacity: .4} 
    to {opacity: 1}
  }
<!DOCTYPE html>
<html lang="ro">
<head>
    <title>CarolandHouse</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="author" content="Penescu Carol-Marian">
    <meta name="description" content="Proiecte Case , Arhitectura , Modelare in AutoCAD">
    
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css" integrity="sha512-+4zCK9k+qNFUR5X+cKL9EIR+ZOhtIloNl9GIKS57V1MyNsYpYcUrUeQc9vNfzsWfV28IaLL3i96P9sdNyeRssA==" crossorigin="anonymous" />
    <link rel="stylesheet" type="text/css" href="css/utilities.css">
    <link rel="stylesheet" type="text/css" href="css/style.css">
    <link rel="stylesheet" type="text/css"href="css/primapagina.css">
    <link rel="stylesheet" type="text/css" href="css/showcase.css">
    <link rel="stylesheet" type="text/css" href="css/cli.css">

</head>
<body>
    
    <script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/2.0.2/anime.min.js"></script>
    
    <div class ="main" >
        <div class="navbar bg-dark ">
        <div class="container flex lead py-1 ">
           <nav>
                <ul>
                    <l1><a href="index.html " class="ml16 flex container lead">Home</a></l1>
                    <li><a href="features.html" class="ml17 flex container lead">Features</a></li>
                    <li><a href="docs.html" class="ml18 flex container lead">Docs</a></li>
                </ul>   
        </nav>
            <div >
                <h1 class="ml5 ">
                    <span class="text-wrapper ">
                      <span class="line line1 "></span>
                      <span class="letters letters-left text-light">Caroland</span>
                      <span class="letters letters-right text-light">House</span>
                      <span class="line line2 "></span>
                    </span>
                  </h1>
                  
            </div>
            <div class="social sm">
                <a href="#"><i class="fab fa-facebook fa-2x"></i></a>
                <a href="#"><i class="fab fa-instagram fa-2x"></i></a>
                <a href="#" class="ml19 flex container" >Contact</a>
            </div>
        </div>
        </div>

        
    <!-- Imagini slideshow -->
    <section class="bg-dark">
        <div class="slideshow-container">
        
        <div class="mySlides fade">
          
          <img src="imaginitest/imagine1birou.jpg" >
          
        </div>
        
        <div class="mySlides fade">
          
          <img src="imaginitest/imagine1casa.jpg" >
          
        </div>
        
        <div class="mySlides fade">
          
          <img src="imaginitest/imagine1hotel.jpg" >
          
        </div>
        </div>
        
 <div style="text-align:center">
          <span class="dot"></span> 
          <span class="dot"></span> 
          <span class="dot"></span> 
        </div>
        </section>
  
     tempora tempore quasi deserunt autem nesciunt hic numquam illum voluptate?
   <!-- Cli -->
    <section class="cli">
        <div class="container grid">
            <img src="images/cli.png" alt="">
            <div class="card">
                <h3>Easy to use, cross platform CLI</h3>
            </div>
            <div class="card">
                <h3>Deploy in seconds</h3>
            </div>
        </div>
    </section>
    
    

    <!-- Footer -->
    <footer class="footer bg-dark ">
        <div class="container flex lead py-1">
           <div class=" flex-basis-3">
               <h1>Despre</h1>
               <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Corporis voluptatum vel praesentium molestias consectetur ea consequuntur a quidem vitae iste?</p>
           </div> 
           <div class="flex-basis-3 text-center">
            <h1>CarolandHouse</h1>
            <p>Copyright &copy; 2021</p>
            </div>
            <div class=" flex-basis-3 text-right">
                <div class="align-better">
                   <span><a href="index.html">Home</a></span>
                   <span><a href="features.html">Features</a></span>
                   <span><a href="docs.html">Docs</a></span>
                </div>
                <div>
                  <a href="#"><i class="fab fa-facebook fa-2x"></i></a>
                  <a href="#"><i class="fab fa-instagram fa-2x"></i></a>
                </div>
            </div>
         </div>
    </footer>
    
    <script src="javascript/javascriptprincipal.js"></script>
    
</div>

</body>
</html>

来源:https://stackoverflow.com/questions/65562748/cant-proprely-align-text-with-animation-in-html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!