简体   繁体   English

CSS3 - 动画比例/悬停时旋转

[英]CSS3 - Animation Scale/Rotate on Hover

I tried and wrote this code but it have a problem, first issue is text inside div will be fuzzy (fluffy)! 我试过写了这段代码,但它有一个问题,第一个问题是div里面的文字会模糊(蓬松)! and second scale animation not play softly, all i want is play animation softly, scale once then rotate infinite on hover. 第二个比例动画不能轻柔地播放,我想要的只是轻柔地播放动画,缩放一次然后在悬停时旋转无限。

@-webkit-keyframes socialspin {
  from {
    -webkit-transform: scale(2) rotate(0deg);
    -moz-transform: scale(2)rotate(0deg);
    -ms-transform: scale(2) rotate(0deg);
    -o-transform: scale(2) rotate(0deg);
    transform: scale(2) rotate(0deg);
  }

   to {
    -webkit-transform: scale(2) rotateY(90deg);
    -moz-transform: scale(2) rotateY(90deg);
    -ms-transform: scale(2) rotateY(90deg);
    -o-transform: scale(2) rotateY(90deg);
    transform: scale(2) rotateY(90deg);
  }
}

Here is JSFiddle Demo 这是JSFiddle演示

here is the example and the point is first to describe all features in the main div as defaults because animation uses main elements rules to calculate time etc. and second point here you used 90 degrees to turn but a complete turning back can be done by 180 degrees which is the angle of a line here is the code 这里是一个例子,第一点是将主要div中的所有特征描述为默认值,因为动画使用主要元素规则来计算时间等。第二点在这里你使用90度转动但是完全回转可以完成180度这里是一条线的角度是代码

--update-- here is the exxample you can see scale animates the problem was in your animation scaling started from 2 and ended by 2 so there was no animation for that --update-- here we go if you run transition first and by the time while transition is running make animation wait by delay time of animation it works fine you can see here --update-- 这里有例子你可以看到缩放动画问题是你的动画缩放从2开始并以2结束所以没有动画--update--如果你先运行转换,我们就去转换运行时的时间使动画等待动画的延迟时间它可以正常工作,你可以在这里看到

 div {
    width: 200px;
    height: 200px;
    background: yellow;
    -webkit-transform:scale(1) rotate(0);
            transform:scale(1) rotate(0);
    margin-left:200px;
    margin-top:50px;
    transition:-webkit-transform .5s linear;
    transition:transform .5s linear;
}

div:hover {
    -webkit-transform:scale(2) rotate(0);
            transform:scale(2) rotate(0);
  -webkit-animation: socialspin 5s linear .5s infinite alternate;
  -moz-animation: socialspin 5s linear .5s infinite alternate;
}


@-webkit-keyframes socialspin {
  from {
    -webkit-transform: scale(2) rotate(0deg);
    transform:scale(2)  rotate(0deg);
  }

   to {
    -webkit-transform: scale(2) rotateY(180deg);
    transform: scale(2) rotateY(180deg);
  }
}

We cannot, as of yet, completely make the font clear. 到目前为止,我们还不能完全使字体清晰。 This is because you are using an animation. 这是因为您正在使用动画。 If there was no spinning, the text would not be fuzzy. 如果没有旋转,文本就不会模糊。 However, we can try using several font smoothing properties to try and combat this. 但是,我们可以尝试使用几种字体平滑属性来尝试解决这个问题。 None of them are very good but they do improve legibility slightly. 它们都不是很好但是它们确实略微提高了易读性。

Regardless, here is the fix for the second part: 无论如何,这是第二部分的修复:

I found a hack. 我找到了一个黑客。 This will remove the blur during the rotation but not during the scaling up. 这将在旋转期间消除模糊,但在放大期间不会消除模糊。

 .square { width:100px; height: 100px; background-color:black; margin: 50px; } p { -webkit-font-smoothing: antialiased; color:white; text-align: center; padding-top: 35px; } .square:hover { -webkit-animation: scale 1s linear 0s 1, spin 1s linear 1s infinite alternate; } .square:hover p{ -webkit-animation: scaletext 1s linear 0s 1; } @-webkit-keyframes scale { from {transform: scale(1); } to{transform: scale(2);} } @-webkit-keyframes scaletext { from {transform: scale(1); } to{transform: scale(1);} } @-webkit-keyframes spin { from {transform: rotateY(0deg) scale(2) ;} to {transform: rotateY(90deg) scale(2);} } 
 <div class="square"> <p>Some text</p> </div> 

(I removed the prefixes to condense the answer) (我删除了前缀以缩小答案)

The best way to have a smooth result is not to have a zoom in (scale=2) but a zoom out (scale=0.5), but of course in the opposite state. 获得平滑结果的最佳方法是不进行放大(缩放= 2)而是缩小(缩放= 0.5),但当然处于相反的状态。

And I don't believe that what you want can be achieved with a single animation. 我不相信你想要的东西可以用一个动画来实现。 I have used 2 elements, and one handles the rotation and the other the scale 我使用了2个元素,一个处理旋转,另一个处理比例

 #container { width: 400px; height: 400px; } #container:hover { -webkit-animation: socialspin 5s linear 0s infinite alternate; } @-webkit-keyframes socialspin { from { -webkit-transform: rotate(0deg); } to { -webkit-transform: rotateY(90deg); } } @keyframes socialspin { from { transform: rotate(0deg); } to { transform: rotateY(90deg); } } #base { width: 400px; height: 400px; background: yellow; transform: scale(0.5); transition: transform 5s; transform-origin: top left; font-size: 200%; } #container:hover #base { transform: scale(1); } 
 <div id="container"> <div id="base"> <br> <br> <br> HELLLLOOOO!!! </div> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM