1

I want to know if there is a way to rotate images without using fotoshop, i want to use css or javascript

The result that im looking for is here

The following solution works but i want to rotate my image without hover property , if i remove the hover here the image dont rotate

<style>

#card img:hover {
transform: rotateY(360deg);
-webkit-transform: rotateY(180deg);
transition-duration: 1.5s;
-webkit-transition-duration:1s;
}
</style>

if found the efect that i want here here

2

5 Answers 5

1

Use CSS' rotate, rotateX, rotateY, rotateZ. Little example:

img {
    transform: inherit;
    transition: all 0.3s;
    width: 100px;
}
img:hover {
    transform: rotateX(45deg)
                rotateY(45deg)
                rotateZ(45deg);
}

Fiddle

rotate is 2D transform method and rotateX, rotateY, rotateZ are 3D transform methods.

W3Schools references:

Sign up to request clarification or add additional context in comments.

Comments

1
img {
    -ms-transform: rotate(45deg); /* IE 9 */
    -webkit-transform: rotate(45deg); /* Chrome, Safari, Opera */
    transform: rotate(45deg);
}

Comments

0

I think you are looking like following code and Here is the fiddle Link and Other Link This might help you!!

<img class="image" src="https://www.arxan.com/wp-content/uploads/assets1/images/demo.png" alt="" width="120" height="120">

<style>
.image {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 120px;
    height: 120px;
    margin:-60px 0 0 -60px;
    -webkit-animation:spin 4s linear infinite;
    -moz-animation:spin 4s linear infinite;
    animation:spin 4s linear infinite;
}
@-moz-keyframes spin { 100% { -moz-transform: rotate(360deg); } }
@-webkit-keyframes spin { 100% { -webkit-transform: rotate(360deg); } }
@keyframes spin { 100% { -webkit-transform: rotate(360deg); transform:rotate(360deg); } }
</style>

Comments

0

Look at this class :

var ImgRotator = {
angle: parseInt(45),
image: {},
src: "",
canvasID: "",
intervalMS: parseInt(500),
jump: parseInt(5),
start_action: function (canvasID, imgSrc, interval, jumgAngle) {
    ImgRotator.jump = jumgAngle;
    ImgRotator.intervalMS = interval;
    ImgRotator.canvasID = canvasID;
    ImgRotator.src = imgSrc;
    var image = new Image();
    var canvas = document.getElementById(ImgRotator.canvasID);
    image.onload = function () {
        ImgRotator.image = image;
        canvas.height = canvas.width = Math.sqrt(image.width * image.width + image.height * image.height);
        window.setInterval(ImgRotator.keepRotating, ImgRotator.intervalMS);
        //theApp.keepRotating();
    };
    image.src = ImgRotator.src;
},
keepRotating: function () {
    ImgRotator.angle += ImgRotator.jump;
    var canvas = document.getElementById(ImgRotator.canvasID);
    var ctx = canvas.getContext("2d");
    ctx.save();
    ctx.clearRect(0, 0, canvas.width, canvas.height);
    ctx.translate(canvas.width / 2, canvas.height / 2);
    ctx.rotate(ImgRotator.angle * Math.PI / 180);
    ctx.drawImage(ImgRotator.image, -ImgRotator.image.width / 2, -ImgRotator.image.height / 2);
    ctx.restore();
}

}

Usage :

ImgRotator.start_action(canvasID, image_url, intervalInMilliseconds, jumgAngle);

HTML (just provide a canvas where you want to rotate the image):

<canvas id="canva" width="350" height="350"></canvas>

Comments

0

Infact Using CSS and jquery we can do better, I mean rotate the whole body on load

function bodyRotate() {
        var angleX = 0, angleY = 0, angleZ = 0;
        var incX = -1, incY = -1, incZ = -1;
        var xStop = -180, yStop = -180, zStop = -180;
        var timerID =
        window.setInterval(function () {
            angleX += incX; angleY += incY; angleZ += incZ;
            var angle = "rotateX(_X_deg) rotateY(_Y_deg) rotateZ(_Z_deg)";
            angle = angle.replace("_X_", angleX).replace("_Y_", angleY).replace("_Z_", angleZ)
            $("body").css({ "transform": angle });
            if (angleX < xStop && angleY < yStop && angleZ < zStop) {
                incX *= -1; incY *= -1; incZ *= -1;
            }
            if (angleX > 0 && angleY > 0 && angleZ > 0) {
                window.clearInterval(timerID);
                $("body").css({ "transform": "rotateX(0deg) rotateY(0deg) rotateZ(0deg)" });
            }
        }, 10);
    }
    $(document).ready(bodyRotate);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.