• Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Help adjusting CSS code (Ken Burns effect)

adamelm

New Coder
I'm using a photo website which allows me to customise with CSS. I'm using the code below to give a ken burns effect (zooms and pans the image).. .however it currently zooms/pans to the top right.. I'd like to adjust the code so it randomly changes which direction it pans/zooms. Anyone able to help? thanks

Code:
@keyframes kenburns {

    0% {

      opacity: 0;

    }

    5% {

      opacity: 1;

    

    }

    95% {

        transform: scale3d(1.5, 1.5, 1.5) translate3d(-190px, -120px, 0px);

          -webkit-transform: scale3d(1.5, 1.5, 1.5) translate3d(-190px, -120px, 0px);

          -ms-transform: scale3d(1.5, 1.5, 1.5) translate3d(-190px, -120px, 0px);

          -moz-transform: scale3d(1.5, 1.5, 1.5) translate3d(-190px, -120px, 0px);

        animation-timing-function: ease-in;

        opacity: 1;

    }

    100% {

          -webkit-transform: scale3d(1.5, 1.5, 1.5) translate3d(-190px, -120px, 0px);

          -ms-transform: scale3d(1.5, 1.5, 1.5) translate3d(-190px, -120px, 0px);

          -moz-transform: scale3d(1.5, 1.5, 1.5) translate3d(-190px, -120px, 0px);

        transform: scale3d(2, 2, 2) translate3d(-170px, -100px, 0px)

      opacity: 0;

    }

 

}
 
This is something you could try out. See more at translate3d() - CSS: Cascading Style Sheets | MDN

Code:
  95% {
    transform: scale3d(1.5, 1.5, 1.5) translate3d(-190px + 50px * Math.random(), -120px + 50px * Math.random(), 0px);
    -webkit-transform: scale3d(1.5, 1.5, 1.5) translate3d(-190px + 50px * Math.random(), -120px + 50px * Math.random(), 0px);
    -ms-transform: scale3d(1.5, 1.5, 1.5) translate3d(-190px + 50px * Math.random(), -120px + 50px * Math.random(), 0px);
    -moz-transform: scale3d(1.5, 1.5, 1.5) translate3d(-190px + 50px * Math.random(), -120px + 50px * Math.random(), 0px);
    animation-timing-function: ease-in;
    opacity: 1;
  }
 
Well, there are some logical errors with your code, you can try the below code to fix this error.

@keyframes kenburns {
0% {
opacity: 0;
}
5% {
opacity: 1;
}
95% {
transform: scale3d(1.5, 1.5, 1.5) translate3d(
calc(-190px + (100px * random())),
calc(-120px + (80px * random())),
0px
);
animation-timing-function: ease-in;
opacity: 1;
}
100% {
transform: scale3d(2, 2, 2) translate3d(
calc(-170px + (120px * random())),
calc(-100px + (70px * random())),
0px
);
opacity: 0;
}
}

Thanks
 
Well, there are some logical errors with your code, you can try the below code to fix this error.

@keyframes kenburns {
0% {
opacity: 0;
}
5% {
opacity: 1;
}
95% {
transform: scale3d(1.5, 1.5, 1.5) translate3d(
calc(-190px + (100px * random())),
calc(-120px + (80px * random())),
0px
);
animation-timing-function: ease-in;
opacity: 1;
}
100% {
transform: scale3d(2, 2, 2) translate3d(
calc(-170px + (120px * random())),
calc(-100px + (70px * random())),
0px
);
opacity: 0;
}
}

Thanks
AFAIK there's no such thing as random() in CSS.

You will either need to use a CSS pre-processor or use JavaScript to generate some form of random value.
 
Top Bottom