简体   繁体   English

动画伪CSS元素-任何框架?

[英]Animate Pseudo CSS elements - any framework?

I was working on creating a bar chart, which had pseudo css elements (::before, ::after). 我正在创建具有伪css元素(:: before,:: after)的条形图。

While I got it to a point where the bars look nice, I can't find a good way to animate the height changes. 当我看到条形看起来不错时,我找不到动画高度变化的好方法。 When I use the animate function, the pseudo elements disappear, and only appear when the animation completes. 当我使用动画功能时,伪元素消失,并且仅在动画完成时出现。 Anyone else has an idea on how to achieve this? 其他人对如何实现这一目标有想法吗? Is there any other animation framework that will render the pseudo elements as well? 还有其他动画框架也可以渲染伪元素吗?

CodePen: http://codepen.io/anon/pen/OyGamW CodePen: http ://codepen.io/anon/pen/OyGamW

HTML 的HTML

<ul><li><div class="fill bar1">100%</div></li></ul>

CSS: CSS:

*{
  padding:0;
  margin: 0;
}
body {
    height: 100%;
    background-repeat: no-repeat;
    background-attachment: fixed;
  background:#cdcdcf;
  overflow: hidden;
}

ul {
  list-style-type:none;
  overflow:hidden;
  padding-left:10px;
  padding-top:40px;
}
li{
float:left;
height:800px;
margin-top: 30px;
}

.fill {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
  width: 90px;
  line-height: 90px;
  position: relative;
  height: 300px;
  top: 161px;
  padding: 0px 0px 0px 8px;
  left: 70px;
  border: none;
  font: normal normal bold 26px/normal Tahoma, Geneva, sans-serif;
  color: rgba(255,255,255,1);
  text-align: left;
  -o-text-overflow: clip;
  text-overflow: clip;
  background: -webkit-linear-gradient(0deg, rgba(255,43,43,1) 0, rgba(209,31,31,1) 100%);
  background: -moz-linear-gradient(90deg, rgba(255,43,43,1) 0, rgba(209,31,31,1) 100%);
  background: linear-gradient(90deg, rgba(255,43,43,1) 0, rgba(209,31,31,1) 100%);
  background-position: 50% 50%;
  -webkit-background-origin: padding-box;
  background-origin: padding-box;
  -webkit-background-clip: border-box;
  background-clip: border-box;
  -webkit-background-size: auto auto;
  background-size: auto auto;
  -webkit-transform:  scaleX(1) scaleY(1) scaleZ(1)  skewY(-3deg);
  transform:  scaleX(1) scaleY(1) scaleZ(1)  skewY(-3deg);
  -webkit-transform-origin: 0 0 0;
  transform-origin: 0 0 0;
  -webkit-box-shadow: 0 11px 18px -5px #841313 inset;
  box-shadow: 0 11px 18px -5px #841313 inset;
}

.fill::before {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
  width: 50%;
  height: 100%;
  position: absolute;
  content: "";
  top: 0;
  left: 0;
  border: none;
  font: normal normal normal 16px/normal "Times New Roman", Times, serif;
  color: rgba(0, 0, 0, 0.901961);
  -o-text-overflow: clip;
  text-overflow: clip;
  background: -webkit-linear-gradient(-180deg, #c62121 0, rgba(132,19,19,1) 100%);
  background: -moz-linear-gradient(270deg, #c62121 0, rgba(132,19,19,1) 100%);
  background: linear-gradient(270deg, #c62121 0, rgba(132,19,19,1) 100%);
  background-position: 50% 50%;
  -webkit-background-origin: padding-box;
  background-origin: padding-box;
  -webkit-background-clip: border-box;
  background-clip: border-box;
  -webkit-background-size: auto auto;
  background-size: auto auto;
  text-shadow: none;
  -webkit-transform:  scaleX(1) scaleY(1) scaleZ(1) translateX(-44px) skewY(20deg);
  transform:  scaleX(1) scaleY(1) scaleZ(1) translateX(-44px) skewY(20deg);
  -webkit-transform-origin: 100% 100% 0;
  transform-origin: 100% 100% 0;
  -webkit-box-shadow: 0 11px 18px -5px #841313 inset;
  box-shadow: 0 11px 18px -5px #841313 inset;
}

.fill::after {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
  width: 100%;
  height: 16.1px;
  position: absolute;
  content: "";
  top: -1px;
  left: 0;
  border: none;
  font: normal normal normal 16px/normal "Times New Roman", Times, serif;
  color: rgba(0, 0, 0, 0.901961);
  -o-text-overflow: clip;
  text-overflow: clip;
  background: rgba(132,19,19,1);
  text-shadow: none;
  -webkit-transform:  scaleX(1) scaleY(1) scaleZ(1) translateX(-50%) translateY(-91%) skewX(70.5deg);
  transform:  scaleX(1) scaleY(1) scaleZ(1) translateX(-50%) translateY(-91%) skewX(70.5deg);
  -webkit-transform-origin: 0 0 0;
  transform-origin: 0 0 0;
}

JS: JS:

$(document).ready(function() {
    setInterval(function() {
        doAnimation();
    },4000);
    doAnimation();
});
function doAnimation() {
  $('.fill').animate({ "height": "150px", "top": "311px"}, 1000);
  $('.fill').delay(1000).animate({ "height": "300px", "top": "161px"}, 1000);
}

Thanks 谢谢

Not exactly sure how GSAP 's TweenMax differs from jQuery 's .animate() method in this particular case but replacing your animation with TweenMax does solve your problem. 在这种特殊情况下,不能完全确定GSAPTweenMaxjQuery.animate()方法有何不同,但是用TweenMax替换动画确实可以解决您的问题。

JavaScript: JavaScript:

TweenMax.to('.fill', 1, {
  height: 150,
  top: 311,
  repeat: -1,
  yoyo: true,
  ease: Expo.easeInOut
});

As a side note, I would strongly recommend using GSAP for all your JS animation needs. 附带说明,我强烈建议您使用GSAP满足所有JS动画需求。 Look into the documentation for available methods and properties. 查看文档中可用的方法和属性。

Here is your forked pen. 是你的分叉笔。

Hope this helps. 希望这可以帮助。

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

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