gpt4 book ai didi

javascript - 翻转后的图像是镜像的,如何使翻转后的图像不镜像?

转载 作者:行者123 更新时间:2023-12-03 05:04:14 24 4
gpt4 key购买 nike

我尝试了各种方法将图像 1 翻转为图像 2,最后决定不使用任何 jquery 插件,并以这种方式完成。使用 JavaScript 将图像 2 插入到“back1”图像类中。但现在翻转后的图像 2 是原始图像 2 的镜像。如何使翻转后的图像不成为镜像?

提前致谢。

wala = document.getElementsByClassName("back1"); 
wala[0].src = "https://placehold.it/300x200";
wala[0].style.cssFloat = "inherit";


function flip() {
$('.cardx').toggleClass('flipped');
}
.containerx {
width: 300px;
height: 200px;
position: relative;
border: 2px solid grey;
}
.cardx {
width: 100%;
height: 100%;
position: absolute;
-webkit-transition: -webkit-transform 2s;
-moz-transition: -moz-transform 2s;
-o-transition: -o-transform 2s;
transition: transform 2s;
-webkit-transform-style: preserve-3d;
-moz-transform-style: preserve-3d;
-o-transform-style: preserve-3d;
transform-style: preserve-3d;

}
.cardx div {
display: block;
height: 100%;
width: 100%;
position: absolute;
-webkit-backface-visibility: hidden;
-moz-backface-visibility: hidden;
-o-backface-visibility: hidden;
backface-visibility: hidden;

}
.cardx .front {
background: url("https://placehold.it/300x200/DCF8FF/333333")
}
.cardx .back {
-webkit-transform: rotateY( 180deg );
-moz-transform: rotateY( 180deg );
-o-transform: rotateY( 180deg );
transform: rotateY( 180deg );

}
.cardx.flipped {
-webkit-transform: rotateY( 180deg );
-moz-transform: rotateY( 180deg );
-o-transform: rotateY( 180deg );
transform: rotateY( 180deg );

}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<section class="containerx">
<div class="cardx" onclick="flip()">
<div class="front"></div>

<div class="back"></div>
<img class= "back1" alt="logo back" />
</div>
</section>

最佳答案

将scaleX(-1)添加到背面元素的CSS变换中以转义翻转的图像。

.cardx .back {
-webkit-transform: rotateY( 180deg ) scaleX(-1);
-moz-transform: rotateY( 180deg ) scaleX(-1);
-o-transform: rotateY( 180deg ) scaleX(-1);
transform: rotateY( 180deg ) scaleX(-1);

}

.cardx.flipped {
-webkit-transform: rotateY( 180deg ) scaleX(-1);
-moz-transform: rotateY( 180deg ) scaleX(-1);
-o-transform: rotateY( 180deg ) scaleX(-1);
transform: rotateY( 180deg ) scaleX(-1);

}

查看更新的代码片段:

wala = document.getElementsByClassName("back1"); 
wala[0].src = "https://placehold.it/300x200";
wala[0].style.cssFloat = "inherit";


function flip() {
$('.cardx').toggleClass('flipped');
}
.containerx {
width: 300px;
height: 200px;
position: relative;
border: 2px solid grey;
}
.cardx {
width: 100%;
height: 100%;
position: absolute;
-webkit-transition: -webkit-transform 2s;
-moz-transition: -moz-transform 2s;
-o-transition: -o-transform 2s;
transition: transform 2s;
-webkit-transform-style: preserve-3d;
-moz-transform-style: preserve-3d;
-o-transform-style: preserve-3d;
transform-style: preserve-3d;

}
.cardx div {
display: block;
height: 100%;
width: 100%;
position: absolute;
-webkit-backface-visibility: hidden;
-moz-backface-visibility: hidden;
-o-backface-visibility: hidden;
backface-visibility: hidden;

}
.cardx .front {
background: url("https://placehold.it/300x200/DCF8FF/333333")
}
.cardx .back {
-webkit-transform: rotateY( 180deg ) scaleX(-1);
-moz-transform: rotateY( 180deg ) scaleX(-1);
-o-transform: rotateY( 180deg ) scaleX(-1);
transform: rotateY( 180deg ) scaleX(-1);

}
.cardx.flipped {
-webkit-transform: rotateY( 180deg ) scaleX(-1);
-moz-transform: rotateY( 180deg ) scaleX(-1);
-o-transform: rotateY( 180deg ) scaleX(-1);
transform: rotateY( 180deg ) scaleX(-1);

}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<section class="containerx">
<div class="cardx" onclick="flip()">
<div class="front"></div>

<div class="back"></div>
<img class= "back1" alt="logo back" />
</div>
</section>

关于javascript - 翻转后的图像是镜像的,如何使翻转后的图像不镜像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42080419/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com