2

I'm using jquery to trigger with a div's hover another div's resize:

$("#lggroup").hover(function()
{
    $("#register").css("width", "200px");
}, function()
{
    $("#register").css("width", "0px");
});

The second div has a transition effect upon it that doesn't affect the change initially but it does after the second hover.

transition: width 0.25s;

Although not breaking, the sudden width expand has an unpleasing effect.

Fiddle: https://jsfiddle.net/tu9keje5/1/

You can see that initially after running the fiddle, the main div expands suddenly because of the gray div expanding suddenly. Afterwards the transition kicks in fine. Any workarounds or causes for this?

2 Answers 2

3

You should give #register an initial width value:

#register {
    transition:width 0.25s;
    width: 0px;
}

working fiddle

Sign up to request clarification or add additional context in comments.

2 Comments

Neat, so jquery/javascript should have an initial value for a css (edit: a defined initial value)
the initial value is undefined :)
1

Your problem is with the CSS, you are trying to animate the width, but the initial with doesn't exist and so there's no animation. For the second time you do it, the width does exist and animates. Change your register css for this (I also placed a height equal to the other divs):

#register
{
    width:0;
    height:400px;
    transition:width 0.25s;
}

The fiddle: https://jsfiddle.net/tfcrdjka/

2 Comments

# is an id, not a css class
Sorry, my fault writing that

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.