Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

transition scale relative to parent

I am using transition:scale(1.2) to hide a div in the bottom left corner of the viewport.

Current & desired results

My current approach is scaling from the center as expected:

Fiddle for 'CURRENTLY'

I want to scale it as if the div would take up the whole screen:

Fiddle for 'DESIRED'

The above is done by scaling the whole body. But instead of using another parent, I was wondering if there is another way to tell CSS in which direction the scaling should occur.

How to use transition:scale(1.2) as seen in DESIRED without using a full-size div?

like image 563
RienNeVaPlu͢s Avatar asked Sep 10 '13 20:09

RienNeVaPlu͢s


People also ask

What does transform scale do?

The transform CSS property lets you rotate, scale, skew, or translate an element. It modifies the coordinate space of the CSS visual formatting model.

What is CSS scale?

The scale() CSS function defines a transformation that resizes an element on the 2D plane. Because the amount of scaling is defined by a vector, it can resize the horizontal and vertical dimensions at different scales. Its result is a <transform-function> data type.

How do you scale HTML?

If your image doesn't fit the layout, you can resize it in the HTML. One of the simplest ways to resize an image in the HTML is using the height and width attributes on the img tag. These values specify the height and width of the image element. The values are set in px i.e. CSS pixels.


1 Answers

You can change the transform-origin:

Something like this should be close to what you are looking for:

-webkit-transform-origin: 120% -40%;

Demo Fiddle

Modified CSS:

#clock {
    position:fixed;
    bottom:8%;
    left:7%;
    color:#fff;
    transition:all .8s;
    -webkit-transition:all .8s;
    transform-origin: 120% -40%;
    -webkit-transform-origin: 120% -40%;
}

body {
    overflow:hidden;
}

body:hover #clock {
    -webkit-transform:scale(1.2);
    transform:scale(1.2);
    opacity:0;
}

Edit Because you are using left/bottom percentage based positioning for the clock, this may be closer to the effect you are looking for. Going back to a center based transform origin and transitioning left/bottom closer to the corner will provide a bit more of the affect that it is being scaled from the upper right corner of the parent.

Demo Fiddle 2

Modified CSS:

#clock {
    position:fixed;
    bottom:8%;
    left:7%;
    color:#fff;
    transition:all .8s;
    -webkit-transition:all .8s;
    transform-origin: center center;
    -webkit-transform-origin: center center;
}

body {
    overflow:hidden;
}
body:hover #clock {
    -webkit-transform: scale(1.2);
    transform: scale(1.2);
    bottom: 1%;
    left: 0%;
    opacity:0;
}
like image 154
dc5 Avatar answered Nov 12 '22 12:11

dc5