How to slide div right to left and left to right smoothly with css

Viewed 48

I'm working on some animation where when the user clicks on any click the page will slide 60px left and when a new page loads it will slide from 60px right to the center

I have created this code but it's not smooth as this reference site: https://www.jacquemus.com/shop/women/tops Is it possible to create animation like this with CSS and JS

var elts = document.querySelectorAll('[data-animate]');
if(elts){
var show = function() { 
  document.getElementById("main").classList.remove('fadeOutLeft');
    document.getElementById("main").classList.add('fadeOutRight');
}

for (var i = elts.length - 1; i >= 0; --i) {
    elts[i].onclick = show;
     }}
 
 .features--show-page-transition_cus{
     -webkit-animation-duration: 2s;
     animation-duration: 2s;
     -webkit-animation-fill-mode: both;
     animation-fill-mode: both;
}
 .header {
    display: flex;
    justify-content: space-evenly;
}

 @-webkit-keyframes fadeOutRight {
     0% {
            opacity: 0.9;
         -webkit-transform: translate(0px, 0);
    }
  
     100% {
         opacity: 0;
         -webkit-transform: translate(-60px, 0);
    }
}
 @keyframes fadeOutRight {
     0% {
         opacity: 0.9;
         -webkit-transform: translate(0px, 0);
    }
  
    
     100% {
         opacity: 0;
         -webkit-transform: translate(-120px, 0);
    }
}
 .fadeOutRight {
     -webkit-animation-name: fadeOutRight;
     animation-name: fadeOutRight;
      
}
 .fadeOutLeft{
     -webkit-animation-name: fadeOutLeft;
     animation-name: fadeOutLeft;
       overflow-x: hidden;
}
 @-webkit-keyframes fadeOutLeft {
     0% {
         opacity: 0;
         -webkit-transform: translate(60px, 0);
    }
     100% {
         opacity: 1;
         -webkit-transform: translate(0px, 0);
    }
}
 @keyframes fadeOutLeft {
     0% {
         opacity: 0;
         -webkit-transform: translate(60px, 0);
    }
     100% {
         opacity: 1;
         -webkit-transform: translate(0px, 0);
    }
}
 
<div class="header">

<a data-animate href="/pages">main</a>
<a data-animate href="/pages">main</a>
<a data-animate href="/pages">main</a>
<a data-animate href="/pages">main</a>
</div>

<main id ="main" class="features--show-page-transition_cus">
   
   
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</p>

</main>
 <script>    
     document.getElementById("main").classList.add("fadeOutLeft");
    </script>

0 Answers
Related