Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery/CSS animate div width from left to right

I'm trying to use jQuery to animate a div with a background picture decreasing in width from left to right whilst being absolutely positioned.

I need to make this compatible with IE8 hence using jQuery.

Here is a basic JSFiddle demo link with what I have so far, but it animates from right to left:

JSFiddle link

jQuery(document).ready(function($){
    $(document).on('click', '.splat', function(e){
        $(this).animate({width:"0px"},800);
    });
});

.splat {
    width: 400px;
    height: 400px;
    background: blue;
    position: absolute;
    top: 100px;
    left: 100px;
}

<div class="splat"><!-- --></div>

I need it going in a different direction, like the following image:

example of what I want to achieve

Hoping someone could point me in the right direction (no pun intended!). Thanks in advance.

like image 325
lemon Avatar asked Jan 09 '14 10:01

lemon


3 Answers

You may use a wrapper and position the child div with right:0.

See this demo

like image 54
otinanai Avatar answered Oct 19 '22 07:10

otinanai


If i can understand your question, solution is replace left with right :)

http://jsfiddle.net/V4XCb/6/

.splat {
    width: 400px;
    height: 400px;
    background: blue;
    position: absolute;
    top: 100px;
    right: 100px;
}
like image 1
edonbajrami Avatar answered Oct 19 '22 07:10

edonbajrami


You can like this:

<div class="box">
    <div class="splat"></div>
</div>

.box{
   width:200px;
   height: 200px;
}
.splat {
    height: 200px;
    width: 100%;
    background: blue;
    float: right;
}
like image 1
chenxiaochun Avatar answered Oct 19 '22 06:10

chenxiaochun