0

I want a smooth transition for my CSS.

I was confused about the transition.

I used the setTimeout method in JavaScript and my CSS works, but it never looks SMOOTH!

Here is my code.

function slideChange(){
    console.log("__start");
    var myVar = setTimeout(change, 1000);
}

function change(){
    var el = document.getElementById('paper slide');
    console.log(el.className);
    el.className = 'paper change';
    console.log(el.className);
    console.log("__finish");
}

function slide(){
    var slide = document.getElementById("paper slide");
    slide.onclick = function(){
        console.log("onclick event start");  
    }; 
}

slideChange();
slide();
.first { 
    width: 100%;
    max-width: 600px;
    max-height: 100px;
    position: relative;
    margin: 0 auto;
    overflow: hidden;
    opacity: 0.5;
}

.change { 
    width: 100%;
    max-width: 600px;
    max-height: 100%;
    overflow: hidden;
    position: relative;
    margin: 5% auto;
    opacity: 1;
}
<div class="paper container" id="paper slide">
  <div class="login-form">
      <input type="text" placeholder="input your email" id="paperInputs1">
  </div>
  <div class="login-form">
      <input type="text" placeholder="input your password" id="paperInputs2">
  </div>
</div>

2 Answers 2

1

You need to use transition to the .change class. transition will give you the smooth change between two state of element

Stack Snippet

function slideChange() {
  console.log("__start");
  var myVar = setTimeout(change, 1000);
}

function change() {
  var el = document.getElementById('paper slide');
  console.log(el.className);
  el.className = 'paper change';
  console.log(el.className);
  console.log("__finish");
}

function slide() {
  var slide = document.getElementById("paper slide");
  slide.onclick = function() {
    console.log("onclick event start");
  };
}

slideChange();
slide();
.first {
  width: 100%;
  max-width: 600px;
  max-height: 100px;
  position: relative;
  margin: 0 auto;
  overflow: hidden;
  opacity: 0.5;
}

.change {
  width: 100%;
  max-width: 600px;
  max-height: 100%;
  overflow: hidden;
  position: relative;
  margin: 5% 0;
  opacity: 1;
  transition: all 1s ease;
}
<div class="paper container" id="paper slide">
  <div class="login-form">
    <input type="text" placeholder="input your email" id="paperInputs1">
  </div>
  <div class="login-form">
    <input type="text" placeholder="input your password" id="paperInputs2">
  </div>
</div>

Sign up to request clarification or add additional context in comments.

Comments

0

add transition and background-color in css to make it more clear:

function slideChange(){
    console.log("__start");
    var myVar = setTimeout(change, 1000);
}

function change(){
    var el = document.getElementById('paper slide');
    console.log(el.className);
    el.className = 'paper change';
    console.log(el.className);
    console.log("__finish");
}

function slide(){
    var slide = document.getElementById("paper slide");
    slide.onclick = function(){
        console.log("onclick event start");  
    }; 
}

slideChange();
slide();
.first { 
    width: 100%;
    max-width: 600px;
    max-height: 100px;
    position: relative;
    margin: 0 auto;
    overflow: hidden;
    opacity: 0.5;
}

.change { 
    width: 100%;
    max-width: 600px;
    max-height: 100%;
    overflow: hidden;
    position: relative;
    margin: 5% auto;
    opacity: 1;
    transition:all 2s ease;
    background-color:pink;
}
<div class="paper container" id="paper slide">
    <div class="login-form">
        <input type="text" placeholder="input your email" id="paperInputs1">
    </div>
    <div class="login-form">
        <input type="text" placeholder="input your password" id="paperInputs2">
    </div>
  </div>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.