Question

I have the following code which works to create the div on click, but I would like the div to slide down slowly and not appear immediately:

function hideshow(which) {

if (!document.getElementById) return
if (which.style.display == "none") which.style.display = "block"
else which.style.display = "none"

I've found some code that appears to do what I'm after, but I'm having difficulty integrating it into my existing code (above):

$(document).ready(function() {
$("#button").toggle(function() {
    $(this).text('Hide');
}, function() {
    $(this).text('show');
}).click(function(){
    $("#hidden_content").slideToggle("slow");
});

I've stuck it on js fiddle if that helps (with supporting css):

http://jsfiddle.net/dRpWv/479/ and http://jsfiddle.net/dRpWv/447/

Was it helpful?

Solution

Use jquery property "slideDown"

My Codepen

function hideshow() {

  var i = 1;
  if (document.getElementById('effet').style.display == "none") {




    $('#effet').slideDown("normal");
    document.getElementById('effet').style.display = "block";
    i = 2;


  } else {

    if (i == 1) {
      $('#effet').slideUp("normal", function () {
        document.getElementById('effet').style.display = "none";
      });
    }

  }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top