Yur*_*nov 2 css svg image css-animations
这是一个代码笔示例https://codepen.io/yury-leonov/pen/rZxxQE
$(".example").on("click", function(e){
$(e.target).toggleClass("reverse");
})Run Code Online (Sandbox Code Playgroud)
.reverse{
transform: scaleX(-1);
}Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div style="width: 700px;height: 700px;margin-left: 100px">
<svg viewBox="-200 0 700 700">
<image class="example" href="https://i.pinimg.com/originals/6f/3d/6a/6f3d6aab605e25af947d804c4a2cb558.jpg" width="150px" height="150px" x="50", y="50"/>
<image class="example" href="https://i.pinimg.com/originals/6f/3d/6a/6f3d6aab605e25af947d804c4a2cb558.jpg" width="150px" height="100px" x="100", y="0"/>
<!--x value can be changed during time-->
</svg>
</div>Run Code Online (Sandbox Code Playgroud)
箭头从其位置移动
箭头反了。留在同一个地方。仅基于 css 执行(无需 js 计算最终 x 值并进行设置)
translateX(-???px) 的硬编码不是一个选项,因为可能有许多对象应该被反转。
使用变换原点和变换框
$(".example").on("click", function(e){
$(e.target).toggleClass("reverse");
})Run Code Online (Sandbox Code Playgroud)
.reverse{
transform: scaleX(-1);
transform-origin: center;
transform-box: fill-box;
}Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div style="width: 700px;height: 700px;margin-left: 100px">
<svg viewBox="-200 0 700 700">
<image class="example" href="https://i.pinimg.com/originals/6f/3d/6a/6f3d6aab605e25af947d804c4a2cb558.jpg" width="150px" height="150px" x="50", y="50"/>
<image class="example" href="https://i.pinimg.com/originals/6f/3d/6a/6f3d6aab605e25af947d804c4a2cb558.jpg" width="150px" height="100px" x="100", y="0"/>
<!--x value can be changed during time-->
</svg>
</div>Run Code Online (Sandbox Code Playgroud)