有没有一种方法可以在不使用插件/ui 套件的情况下在 jquery 中对悬停类进行动画处理?
我对
有翻转效果,并且我希望背景在悬停时能够很好地淡入/淡出。Some header
它的正常状态是:
h3 {
background: none;
}
悬停是一个 css3 动画:
h3:hover {
background-image: linear-gradient(bottom, #FFFFFF 25%, #FCFCFC 100%);
background-image: -o-linear-gradient(bottom, #FFFFFF 25%, #FCFCFC 100%);
background-image: -moz-linear-gradient(bottom, #FFFFFF 25%, #FCFCFC 100%);
background-image: -webkit-linear-gradient(bottom, #FFFFFF 25%, #FCFCFC 100%);
background-image: -ms-linear-gradient(bottom, #FFFFFF 25%, #FCFCFC 100%);
background-image: -webkit-gradient(
linear,
left bottom,
left top,
color-stop(0.25, #FFFFFF),
color-stop(1, #FCFCFC)
);
}
因为我有很多规则 - 我不能在 jQuery simple animatie 中做到这一点(或者我可以吗?)。
可以在不使用任何插件或 jQuery ui 工具包的情况下完成吗?或者 - 是否可以在 css3 动画中实现它?我尝试通过添加到 h3 这段代码来实现 css3 动画,但它产生了奇怪的效果,而且根本不是简单的淡入淡出:
h3 {
-webkit-transition: all 0.1s ease-out; /* Saf3.2+, Chrome */
-moz-transition: all 0.3s ease-out; /* FF4+ */
-ms-transition: all 0.3s ease-out; /* IE10? */
-o-transition: all 0.3s ease-out; /* Opera 10.5+ */
transition: all 0.3s ease-out;
}
谢谢, 阿隆
I have a roll over effect on a <h3>Some header</h3>
and I want the background to fadein/fadeout nicely on hover.
its normal state is:
h3 {
background: none;
}
and the hover is a css3 animation:
h3:hover {
background-image: linear-gradient(bottom, #FFFFFF 25%, #FCFCFC 100%);
background-image: -o-linear-gradient(bottom, #FFFFFF 25%, #FCFCFC 100%);
background-image: -moz-linear-gradient(bottom, #FFFFFF 25%, #FCFCFC 100%);
background-image: -webkit-linear-gradient(bottom, #FFFFFF 25%, #FCFCFC 100%);
background-image: -ms-linear-gradient(bottom, #FFFFFF 25%, #FCFCFC 100%);
background-image: -webkit-gradient(
linear,
left bottom,
left top,
color-stop(0.25, #FFFFFF),
color-stop(1, #FCFCFC)
);
}
since I have so many rules - I can't do it in jQuery simple animatie (or can I?).
Can it be done without using any plugins or jQuery ui kits? Or - is it possible to achieve it in a css3 animation? I tried css3 animtation by adding to h3 this code, but it made weird effects and not at all the simple fadein:
h3 {
-webkit-transition: all 0.1s ease-out; /* Saf3.2+, Chrome */
-moz-transition: all 0.3s ease-out; /* FF4+ */
-ms-transition: all 0.3s ease-out; /* IE10? */
-o-transition: all 0.3s ease-out; /* Opera 10.5+ */
transition: all 0.3s ease-out;
}
thanks,
Alon
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用 jQuery 来实现类似 this 的操作。
CSS:
JavaScript:
You can do it like this with jQuery.
CSS:
JavaScript:
这也可以在没有 jQuery 的纯 CSS2.1 + CSS3 中完成。
http://cssdesk.com/MGyKp
顶部没有额外的标记,底部有额外的跨度。遗憾的是,它在 Safari 中运行不佳,但在 Firefox 中运行良好。
对于跨浏览器体验,本线程中的 jQuery 解决方案是最好的。
This could also be done in pure CSS2.1 + CSS3 without jQuery.
http://cssdesk.com/MGyKp
The top is without extra markup, the bottom is with an extra span. It does not work well in Safari, sadly, but fine in Firefox.
For the cross-browser experience, the jQuery solution in this thread is the best.
我会创建 2 个标题,1 个带背景,1 个不带背景。使用 jQuery 在两者之间淡入淡出。据我所知,适用于所有浏览器。
您可以将多个属性传递给 jQuery 动画函数 (http://api.jquery.com/animate/)。不确定是否可以为渐变背景设置不透明度动画?
I would create 2 headers, 1 with the background, 1 without. Fade between the 2 using jQuery. Would work with all browsers afaik.
You can pass multiple attributes to a jQuery animation function (http://api.jquery.com/animate/). Not sure if you can animate opacity for gradient backgrounds though?