jQuery .show() function question

Here is a code snippet I got from jQuery's website at http://api.jquery.com/show/. The show() function clearly animates by expanding the width, height, and  opacity in a certain way. Is there a way to alter that? For example, what if I wanted only the height to expand and not the width, or vice versa?

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>show demo</title>
  <style>
  p {
    background: yellow;
  }
  </style>
  <script src="//code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<button>Show it</button>
<p style="display: none">Hello  2</p>
<script>
$( "button" ).click(function() {
  $( "p" ).show( "slow" );
});
</script>
</body>
</html>

Open in new window

elepilAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GaryCommented:
How can you have height without width when the element is 100% wide?
If you don't want 100% width then use inline-block in the css or use an inline element.
0
elepilAuthor Commented:
You can set the width and height (or line-height) to a fixed pixel value prior.

You didn't answer my question though. Is there a way to alter the way jQuery handles it's show()/hide() animation in terms of how it manipulates the properties? (Aside from going into the jQuery code and modifying it there, of course.)
0
GaryCommented:
http://jsfiddle.net/d388t1oL/3/

$( "button" ).click(function() {
    $( "p" ).animate( {"height":"toggle" });
});

Open in new window

0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

elepilAuthor Commented:
Gary, I think you're missing my point. I'm not trying to make an animation with the width preset and the height expanding downward; that was just an animation variant example I gave to stress the point that jQuery's animation choreography may not be what I want. You used the animate() function, which wasn't even what I was asking about.

The point of my question is, am I stuck with the way jQuery 'choreographs' the show() function (without having to modify jQuery itself)? That's what I want to know from people more experienced than I am at jQuery.
0
GaryCommented:
Uh?? Then what do you want
what if I wanted only the height to expand and not the width
0
elepilAuthor Commented:
I just explained it to you. Why do I get a feeling you don't read my entire post?
0
GaryCommented:
I think you should reread your own comment because it makes no sense.
You want the .show() to do something it's not designed to do - what that may be is anyones guess
0
RobOwner (Aidellio)Commented:
I feel this is relevant that in the api documentation: http://api.jquery.com/show/

When a duration, a plain object, or a "complete" function is provided, .show() becomes an animation method. The .show() method animates the width, height, and opacity of the matched elements simultaneously.

So not only is it built on the animation class, it is predefined to animate the width, height and opacity only and at the same rate.  So it other words you can't edit it.

You will have to build your own animation using the animation function: http://api.jquery.com/animate/

.show() is simply a predefined animate() function call. Does that make sense?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
elepilAuthor Commented:
Rob Jurd, you answered my question directly, and that was what I wanted to know, as you said succinctly -- "it is predefined to animate the width, height and opacity only and at the same rate.  So it other words you can't edit it."
0
GaryCommented:
$( "p" ).show("slow")

does exactly the same as, and calls the same functions as

$( "p" ).animate( {"height":"toggle","width":"toggle" });

as pointed out here

.show() isn't some magical function, both examples above call the same functions, .show() is just a shorthand function
0
RobOwner (Aidellio)Commented:
elepil,

Thanks for the points and I'm glad you understood how .show() now works.  I do feel that I just re-jigged slightly what Gary had already said, and his examples of the .animate() functions do now tie in with what we've said.  They also show you how you can essentially modify the .show() function, which was your original question.

If it's ok with you, would a split of the points be ok?

Rob
0
elepilAuthor Commented:
Rob, here is a portion of my original post.

"The show() function clearly animates by expanding the width, height, and  opacity in a certain way. Is there a way to alter that? For example, what if I wanted only the height to expand and not the width, or vice versa?"


Gary answered with the animate() function, which was not the function I was asking about. When you said, "it is predefined to animate the width, height and opacity only and at the same rate.  So it other words you can't edit it.", you said the two key things that I needed to know.

Gary has been pretty good in answering a lot of my past questions, and he has gotten quite a bit of points from me. I like to be generous, but I have to be fair. I give out points not only based on whether or not a responder gave me a correct answer, I also weight them based on how succinct and clear they were. In this case, you satisfied both criteria.

Had Gary just said I can't change it but have to use a different function, he would've gotten points. I go through great pains to make my question brief, simple, and specific, then I cross my fingers and hope responders would read it carefully. You apparently did, and your answer was concise, to-the-point, leaving me with nothing more to ask, that's why you got all the points.

For whatever it's worth, you are clearly a noble man for this request you made.
0
RobOwner (Aidellio)Commented:
Elepil,
Thank you for taking the time to respond and certainly understand and appreciate your point of view.

Rob
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.