lemon
lemon

Reputation: 605

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.

Upvotes: 5

Views: 19835

Answers (5)

Arul
Arul

Reputation: 491

You can use Scale Effect in Jquery :

jQuery(document).ready(function($){
    $(document).on('click', '.splat1', function(e){
        $(this).hide("scale");
    });    
});

Fiddle : http://jsfiddle.net/V4XCb/14/

Upvotes: 0

Jai
Jai

Reputation: 74738

If you could wrap your elem with a wrapper which is relative positioned element and do the following:

.splatWrapper {
    width: 400px;
    height: 400px;
    background: green;
    position: relative; //<-----needed
    top: 100px;  //<------------needed
    left: 100px; //<------------needed
 }
 .splat{
    width: 400px;
    height: 400px;
    background: blue;
    position: absolute;
    top: 0;     //<----------needed
    right: 0;   //<----------needed
 }

Try this fiddle

Upvotes: 1

chenxiaochun
chenxiaochun

Reputation: 11

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;
}

Upvotes: 1

otinanai
otinanai

Reputation: 4023

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

See this demo

Upvotes: 5

edonbajrami
edonbajrami

Reputation: 2206

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;
}

Upvotes: 1

Related Questions