JavaScript Make input box slide in from left or right

here is my code: https://jsfiddle.net/hsf4yo5t/

HTML code:

<input type="button" id="my-button" value="Show text input">
<input type="text" id="my-input">

CSS code:

#my-input {
  visibility: hidden;
}

Javascript code:

document.getElementById('my-button').onclick = function() {
    document.getElementById('my-input').style.visibility = 'visible';
}

when I click the button, it shows. but how can i make it slide out using javascript OR jquery?

Answer:1

Here's a jQuery solution: It animates the opacity and the left parameter, which initially is set to a (negative) value so that the input field is off the screen (you have to use position: relative to make that possible):

$("#my-button").click(function() {
  $("#my-input").animate({
    'left': '0px',
    'opacity': '1'
  });
});
#my-input {
  position: relative;
  left: -300px;
  opacity: 0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="button" id="my-button" value="Show text input">
<input type="text" id="my-input">
Answer:2

I am implementing server-side rendering using redux-saga. I am following the "real world" example provided in the redux-saga repository. node.js entry-point uses react.js renderToString to render ...

I am implementing server-side rendering using redux-saga. I am following the "real world" example provided in the redux-saga repository. node.js entry-point uses react.js renderToString to render ...

I have a problem programming object-oriented in Javascript. I have the following: class Foo{ constructor(){...} ... a_needed_method(){...} ... a_method(){ ... ...

I have a problem programming object-oriented in Javascript. I have the following: class Foo{ constructor(){...} ... a_needed_method(){...} ... a_method(){ ... ...

  1. access parent this javascript
  2. access parent this
  3. react access parent this
  4. access the parent portal
  5. java access parent class this

I have an application where there could be anywhere between 1 - 30 POST ajax calls happening in parallel. Also these calls are being made to the same method in the controller. But when there are more ...

I have an application where there could be anywhere between 1 - 30 POST ajax calls happening in parallel. Also these calls are being made to the same method in the controller. But when there are more ...

I have attached a picture of the click action I want to run from the Chrome console, with various values passed. The button is highlighted in gray top right in the inspect element. It is the ...

I have attached a picture of the click action I want to run from the Chrome console, with various values passed. The button is highlighted in gray top right in the inspect element. It is the ...

  1. access angular controller from console
  2. access angular controller from javascript
  3. access angular controller variable in javascript
  4. access angular controller
  5. access controller scope angularjs
  6. access angularjs controller from console
  7. angular access controller scope from outside
  8. angular access controller from another module
  9. angular access controller variable
  10. angular access controller from directive
  11. angular access controller from html
  12. angular access controller variable from directive
  13. angular access controller method
  14. angular access controller functions
  15. angularjs access controller scope from directive
  16. angularjs access controller from directive
  17. angularjs access controller scope from service
  18. angularjs access controller from javascript
  19. angularjs access controller variable from directive
  20. angularjs access controller