【问题标题】:How do I make my image go FROM rotated to straight (HTML, CSS, JS,)如何使我的图像从旋转到直(HTML,CSS,JS,)
【发布时间】:2020-12-05 14:10:15
【问题描述】:

在我网站的主页上,我有一个图像在您单击它之前应该是“损坏的”,我希望它从 23 度开始然后旋转到 0 并停留在那里。有任何想法吗?抱歉,如果这很难阅读,但这是我所拥有的:

相关 CSS:

<style>
                 .crossRotate {
                -webkit-transition-duration: 1s;
                -moz-transition-duration: 1s;
                -o-transition-duration: 1s;
                 transition-duration: 1s;
                -webkit-transition-property: -webkit-transform;
                -moz-transition-property: -moz-transform;
                -o-transition-property: -o-transform;
                 transition-property: transform;
                 transform: rotate(23deg);
            }
            
            /*.crossRotate:active {
                transform: rotate(23deg);
                -webkit-transform: rotate(23deg);
                -ms-transform: rotate(23deg);
                 transform: rotate(23deg);
            }*/
            .crossRotate:active {
                transform: rotate(0deg);
                -webkit-transform: rotate(0deg);
                -ms-transform: rotate(0deg);
                 transform: rotate(0deg);
                 font-size:50%;
            }
            nuggets{
                max-width:20px;
                max-height:15px;
                font-size:20px;
            }
</style>

相关 JS(在头部):

          <script>
              $( ".crossRotate" ).click(function() {
                    if (  $( this ).css( "transform" ) == 'none' ){
                        $(this).css("transform","rotate(0deg)");
                    } else {
                        $(this).css("transform","" );
                    }
                });
          </script>
    </head>

相关 HTML:

        <p><img class="crossRotate" src="images/example.jpg" alt="ExamplerAlt"></p>

记住:我希望它从 23 度变为 0 度并保持在 0 度

谢谢!

【问题讨论】:

  • 我希望它在点击后保持为 0
  • 如果您将其发布到 jsfiddle 或类似的沙箱。与您交流可行的解决方案会更容易。

标签: javascript html css rotation


【解决方案1】:

请试试这个

首先设置rotate 23deg。然后点击active之间的图片添加类

其次,通过.crossRotate.active检查css中的活动类 然后设置rotate 0deg.

$( ".crosslink" ).click(function(e) {
  e.preventDefault();
  $(this).children('.crossRotate').addClass("active");
});
.crossRotate{
  -webkit-transition-duration: 1s;
  -moz-transition-duration: 1s;
  -o-transition-duration: 1s;
  transition-duration: 1s;
  -webkit-transform: rotate(23deg);
  -moz-transform: rotate(23deg);
  -o-transform: rotate(23deg);
  transform: rotate(23deg);
}
.crossRotate.active {
  transform: rotate(0deg);
  -webkit-transform: rotate(0deg);
  -ms-transform: rotate(0deg);
  -o-transform: rotate(23deg);
}
.crosslink{outline:none;}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<a href="#" class="crosslink">
<img class="crossRotate" src="https://i.stack.imgur.com/PR5cj.jpg" alt="ExamplerAlt"></p></a>

【讨论】:

  • 对不起,我试过了,还是不行。它保持 23 度,我希望它被点击,然后更改为 0 并保持 0。我不确定为什么它不起作用
  • 在活动类中单击按钮时添加类active在css中设置0度
  • 等等检查一下,Des JS 进入头脑了吗?因为它仍然不适合我......
  • 请在 head 部分添加 jquery cdn &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"&gt;&lt;/script&gt;
  • 不,仍然无法正常工作,是我的笔记本电脑有问题吗?这是网站主页,请检查它是否在您的设备上运行(它仍在 WIP 中,所以有些页面看起来很奇怪)thesam.co.nz/Something-funny.html
【解决方案2】:

尝试使用@keyframescss 属性。你可以使用

@keyframes animation_name{
  from{
    transform: rotate(23deg);
  }
  to{
    transform: rotate(0deg);
  }
}

您可以使用 transform: rotateX(23deg)transform: rotateY(23deg)或 3d 。让我知道它是否有效。

【讨论】:

  • @KingSam 我对 JS 一无所知,但我已经准备好你的答案了。在我的 twitter 帐户上给我发消息,我不仅会分享代码,还会解释。 JeetViramgama 是我的 Twitter 个人资料。
猜你喜欢
  • 2018-10-22
  • 1970-01-01
  • 2010-12-04
  • 1970-01-01
  • 1970-01-01
  • 2012-11-10
  • 2013-12-11
  • 1970-01-01
  • 2018-02-21
相关资源
最近更新 更多