Animate width toggle from right to left in jQuery

devnull Ψ

I want to slide a hidden (display:none) div block from right to left using jQuery. It should appear when a user hovers on this block. Here's code:

$('.wrapper').hover(function () {
    $(this).children('.item').stop(true, true).animate({width:'toggle'}, 400);
});

This code works fine, but it slides from left to right, and I want it to slide from right to left. How can I 'reverse' it?

YakovL

The animation makes width of the element change and when it is positioned in a usual manner, it gets shrinked to the left side (think of it this way: where will your block end up if it get 50% width?). You can position the div in another way, say with float: right; and in this case it will be shrinked to the right side.

Here's a snippet that illustrates this:

window.toggle = function() {
	jQuery(".toggledOne, .toggledAnother").stop(true, true).animate({width:'toggle'}, 400);
}
.wrapper,
.toggledOne,
.toggledAnother {
    width: 100%;
}

.wrapper {
    height: 2em;
}
.toggledOne,
.toggledAnother {
    height: 1em;
}
.toggledOne {
    background-color: red;
}

.toggledAnother {
    float: right;
    background-color: green;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<a onclick="window.toggle();">click me</a>
<div class="wrapper">
    <div class="toggledOne"></div>
    <div class="toggledAnother"></div>
</div>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Animate width from right to left

From Dev

Animate width from right to left

From Dev

jQuery/CSS animate div width from left to right

From Dev

jQuery animate to left or right from variable

From Dev

JQuery animate div from right to left with smoothness

From Dev

Can't toggle from right to left Jquery

From Dev

Animate window width right to left

From Dev

jQuery animate a responsive div right and left by it's width

From Dev

jQuery, shrink div width from left to right

From Dev

Toggle From Right to Left

From Dev

jquery animate (left to right) loop

From Dev

Append div element and then animate from right to left using JQUERY

From Dev

Animate div from left to right

From Dev

Animate SVG from left to right

From Dev

Animate div from left to right

From Dev

How to animate 2 css layouts from left to right or from right to left with jquery?

From Dev

jQuery : Toggle Sliding A div from left to right over another div

From Dev

toggle input from right to left

From Dev

Animate div from right to left and then from left to right again

From Dev

How to animate a background image from left to right and from right to left

From Dev

Animate Chart Bars from Left to Right

From Dev

Animate Chart Bars from Left to Right

From Dev

iOS: Animate color change from left to right

From Dev

Animate SVG fill from left to right

From Dev

How to animate a LAYOUT from right to left?

From Dev

animate from the center to the left with jquery

From Dev

Toggle menu from right instead of left

From Dev

jQuery slideout from left toggle

From Dev

jQuery slideout from left toggle