JavaScript jQuery slideDown not functioning correctly

I wish to animate a div to make it appear and slide down with jQuery.

I have got my script to work where you hover over an image and another div slides in, should the user leave the mouse hover, the div will slide up and disappear.

Problem:

The first time i hover over the image, nothing happens. I have to leave my mouse and hover over it a second time for the effect to start working, I dont get why this is???

jQuery:

function show_action(){
    $(function(){
        $(".action").hide();
        $(".logo").hover(
            function(){ $(".action").slideDown(); },
            function(){ $(".action").slideUp(); }
        );
    });
}

CSS:

#action_text{
    display:none;
}

HTML:

<div class="center_container">
  <div class="action" id="action_text"><span>Click To Upload</span></div>
  <img src="images/logo.png" class="logo" onmouseover="show_action();"> 
</div>
Answer:1

No need to call .hide() on the .action element. Just give it display: none in your css, so that it will not show when the page loads. That way, you don't need the .stop() to clear the animation queue, and it also prevents a 'flicker' effect where your .action element will show up when the page loads for a brief moment until .hide() gets called.

$(document).ready(function() {
  $('.logo').hover(
    function() {
      $(".action").slideDown();
    },
    function() {
      $(".action").slideUp();
    }
  );
});
.action {
  width: 100%;
  background-color: red;
  display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
  <span class="logo">LOGO</span>
</div>

<div class="action">
  <span>Action</span>
</div>
Answer:2

I have been trying to grab json data from an API and display it using the map() function. Unfortunately the API returns data in the format: { "type": ..., "value": ... }. The second object value ...

I have been trying to grab json data from an API and display it using the map() function. Unfortunately the API returns data in the format: { "type": ..., "value": ... }. The second object value ...

  1. displaying json data in html
  2. displaying json data in react js
  3. displaying json data in angular
  4. displaying json data in html table
  5. displaying json data in php
  6. displaying json data in html using javascript
  7. displaying json data in python
  8. displaying json data in angular component
  9. displaying json data in chart js
  10. displaying json data in angular 6
  11. displaying json data
  12. displaying json data in javascript
  13. displaying json data in html using jquery
  14. displaying json data in datatable
  15. displaying json data in table
  16. displaying json data in android
  17. displaying json data in angularjs
  18. displaying json data in ionic
  19. displaying json data in jsp
  20. jquery displaying json data

Hi it is very simple question, but I didn't find the answer fit in my situation. In my jQuery dialog I have buttons which is update and close. User click 'update button' then on code behind I need ...

Hi it is very simple question, but I didn't find the answer fit in my situation. In my jQuery dialog I have buttons which is update and close. User click 'update button' then on code behind I need ...

I am attempting to pass 2 arrays to a function that filters through array 1 by array 2, then returns the filtered results. I am not understanding why I am getting the error: "Uncaught TypeError: arr2....

I am attempting to pass 2 arrays to a function that filters through array 1 by array 2, then returns the filtered results. I am not understanding why I am getting the error: "Uncaught TypeError: arr2....

  1. array some function example
  2. array some function in java
  3. typescript array some function
  4. js array some function
  5. array some arrow function
  6. php array some function
  7. angular array some function
  8. some array related functions in php
  9. array.some is not a function
  10. javascript array some arrow function

I have a 10 x 10 board and a button (in the demo given below I've minimized that to 3 x 3 ). When users click on the button the system generates a random number 1 to 9. document.getElementById(...

I have a 10 x 10 board and a button (in the demo given below I've minimized that to 3 x 3 ). When users click on the button the system generates a random number 1 to 9. document.getElementById(...