jquery/css:如何在 div 的背景颜色上实现擦除左动画
这是我的 css,
#Slide {
background: none;
height: 30px;
width: 140px;
}
#Slide.Selected {
background: #ff0;
}
我希望每当我向 #Slide
添加/删除类 Selected
时,背景颜色属性都会通过从左擦除/从右擦除来实现动画效果。通常,背景颜色只是出现然后消失。如果使用 css 类时这不可行,是否可以使用 jquery .animate()
函数?或者可能是 css3 transition
属性?
有人有什么建议吗
Here's my css
#Slide {
background: none;
height: 30px;
width: 140px;
}
#Slide.Selected {
background: #ff0;
}
I want that whenever I add/remove the class Selected
to #Slide
, the background-color property is animated by wiping in from left/wiping out to right. Normally, the background-color just appears and disappears. If this is not doable while using css class, is it possible by using jquery .animate()
function? or may be css3 transition
property?
Any suggestions somebody
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是我做的一个wipe_left函数,当我寻找自己的答案时看到了你的问题:
Fiddle在这里: http ://jsfiddle.net/LostInDaJungle/da16gx9n/1/
Here's a wipe_left function I did, saw your question when I was looking for my own answer:
Fiddle is here: http://jsfiddle.net/LostInDaJungle/da16gx9n/1/
可以使用 CSS 伪元素和过渡创建平滑的背景擦除效果。
首先将背景伪元素注入主容器中。然后,当将类添加到容器中时,使用变换将背景移开。
一些小注意事项:
overflow:hidden
和position:relative
。Codepen 示例
A smooth background wipe effect can be created using CSS pseudo-elements and transitions.
First inject a background pseudo-element into your main container. Then when a class is added to the container, use a transform to move that background out of the way.
A few small considerations:
overflow: hidden
andposition: relative
.Example on Codepen
您无法使用 jQuery 或 CSS3 动画在背景颜色上执行擦除动画。
要获得这种视觉效果,您有几个选择。您可以对位于现有元素后面的整个单独元素进行擦除过渡,以模拟背景。或者,您可以使用所需颜色和大小的背景图像,并对背景位置进行动画处理以模拟擦除。
You cannot do a wipe animation on background color with either jQuery or CSS3 animations.
To get this visual effect, you have a couple options. You can do a wipe transition on a whole separate element that is positioned behind your existing element such that it simulates the background. Or, you may be able to use a background image of the desired color and size and animate the background position to simulate a wipe.