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
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
Share Improve this question edited Apr 13, 2017 at 12:46 CommunityBot 11 silver badge asked Mar 29, 2016 at 12:39 Guillermo Nahuel VarelliGuillermo Nahuel Varelli 3181 gold badge14 silver badges34 bronze badges 2-
2
transform : rotate(DEGREE)
– Rayon Commented Mar 29, 2016 at 12:39 - Go there if you want to chat about it – PDKnight Commented Mar 29, 2016 at 13:13
5 Answers
Reset to default 1Use 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:
- 2D transforms
- 3D transforms
img {
-ms-transform: rotate(45deg); /* IE 9 */
-webkit-transform: rotate(45deg); /* Chrome, Safari, Opera */
transform: rotate(45deg);
}
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./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>
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>
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);
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745638318a4637531.html
评论列表(0条)