user951042
user951042

Reputation:

Jquery animate sliding effect

i have a textarea and on click that textarea a div fadesIn and slides to the right and on blur it fades out but the problem is when you click it again it fadesIn from the point it was originally displaced. Is there a way to make it start from its original postion?

My html

 <textarea id="textarea" cols="50" rows="15" style="margin-top:100px;"></textarea>
 <div id="block" style="display:none;">
       <h1>Tips</h1>
         <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
         </p></div>

My CSS

#block {
  position:absolute;
  left:400px;
  top:80px;
  width:500px;
  margin:0px;
  z-Index: 100;
  background-color:#FBCA8F;
color: #444;
border: 1px solid #000;
padding:10px;
line-height: 150%;
}

Javascript

$("#textarea").focus(function(){
  $("#block").fadeIn(10).animate({"left": "+=30px" },"fast");
});
 $("#textarea").blur(function(){ $("#block").animate({"left": "-=5px" },"fast").fadeOut(10);
 });

Originally the textarea slide description (http://www.taskrabbit.com/tasks/newfrom=howitworks) on that site was what i was aiming for but this is only what i could come up with. I'd really appreciate any help. Many Thanks.

Upvotes: 0

Views: 240

Answers (1)

GregM
GregM

Reputation: 2654

Yeah in the javascript change the blucr function like this :

$("#textarea").blur(function(){ $("#block").animate({"left": "-=5px" },"fast").fadeOut(10 , function(){ // put back $("#block") to his start position });});

You have a callback on the fadeOutfunction, so when all is done, you can put back everything where you want it to be

Upvotes: 1

Related Questions