Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery fade out sliding left

Tags:

jquery

css

I want to make some divs fade out and sliding left at the same time, which is much like dismissing notification cards on Android.

I searched and found some jquery codes.

$('#clickme').click(function(){   
$('#book').animate({
      opacity: 'hide', // animate slideUp
      margin: 'hide',
      padding: 'hide',
      height: 'hide' // animate fadeOut
    }, 'slow', 'linear', function() {
      $(this).remove();
    });
});

but this code makes the div(#book) fade out with sliding up, not left (or right). I read the document about .animate() but I couldn't find how to do that.

like image 814
Junsung Park Avatar asked Jul 27 '15 12:07

Junsung Park


People also ask

How do I fadeOut text in jQuery?

The jQuery fadeOut() method is used to fade out a visible element. Syntax: $(selector).fadeOut(speed,callback); The optional speed parameter specifies the duration of the effect.

What is the syntax of jQuery fadeToggle () method?

jQuery fadeToggle() If the elements are faded in, it will make them faded out and if they are faded out it will make them faded in. Syntax: $(selector). fadeToggle();

How does jQuery fadeOut work?

fadeOut() method animates the opacity of the matched elements. Once the opacity reaches 0, the display style property is set to none , so the element no longer affects the layout of the page. Durations are given in milliseconds; higher values indicate slower animations, not faster ones.

What is fadeIn in jQuery?

jQuery fadeIn() Method The fadeIn() method gradually changes the opacity, for selected elements, from hidden to visible (fading effect). Note: Hidden elements will not be displayed at all (no longer affects the layout of the page). Tip: This method is often used together with the fadeOut() method.


2 Answers

You can try this :

$('#clickme').click(function() {
  $('#book').animate({
    opacity: 0, // animate slideUp
    marginLeft: '-200px'
  }, 'slow', 'linear', function() {
    $(this).remove();
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id='clickme'>Click me!!!</button>
<div id='book' style='width:200px; height:200px; background:black; border:greenyellow 4px solid;position:absolute; top:40px;'>Book</div>

Note:

The target element which should be animated has to be positioned relatively/absolutely.

like image 160
Jai Avatar answered Oct 20 '22 04:10

Jai


check if this helps you

$(document).ready(function(){
    $("#flip").click(function(){
        $("#panel").hide("slide", { direction: "left" }, 1000);
    });
});
#panel, #flip {
    padding: 5px;
    text-align: center;
    background-color: #e5eecc;
    border: solid 1px #c3c3c3;
}

#panel {
    padding: 50px;
    display: block;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script> 
<div id="flip">Click to slide left panel</div>
<div id="panel">Hello world!</div>
like image 26
Manoj Dhiman Avatar answered Oct 20 '22 04:10

Manoj Dhiman