有没有一种方法来动画的悬停类在jquery中不使用插件/ui工具包
Is there a way to animate a hover class in jquery without using plugins/ui kits?
我在<h3>Some header</h3>
上有一个滚动效果,我想让背景在悬停时淡入/淡出。
其正常状态为:
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简单的动画(或者我可以吗?)。
可以不使用任何插件或jQuery ui工具包?或者-是否有可能在css3动画中实现?我尝试了css3动画添加到h3这段代码,但它产生了奇怪的效果,而不是简单的淡出:
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;
}
谢谢,阿龙
使用jQuery可以这样做。
CSS:h3 {
margin: 10px;
}
div.h3_bg {
background: linear-gradient(bottom, #FF0000 25%, #FCFCFC 100%);
background: -o-linear-gradient(bottom, #FF0000 25%, #FCFCFC 100%);
background: -moz-linear-gradient(bottom, #FF0000 25%, #FCFCFC 100%);
background: -webkit-linear-gradient(bottom, #FF0000 25%, #FCFCFC 100%);
background: -ms-linear-gradient(bottom, #FF0000 25%, #FCFCFC 100%);
background: -webkit-gradient(
linear,
left bottom,
left top,
color-stop(0.25, #FF0000),
color-stop(1, #FCFCFC)
);
}
JavaScript: $("h3").each(function() {
$("body")
.append(
$('<div>', {class:"h3_bg"})
.width($(this).outerWidth())
.height($(this).outerHeight())
.hide()
.css({
position: "absolute",
top: $(this).offset().top,
left: $(this).offset().left,
zIndex: -1
})
);
$(this).hover(
function() {
$("div.h3_bg").eq($(this).index()).fadeIn();
},
function() {
$("div.h3_bg").eq($(this).index()).fadeOut();
}
);
});
这也可以在没有jQuery的纯CSS2.1 + CSS3中完成。
http://cssdesk.com/MGyKp顶部没有额外的标记,底部有一个额外的span。遗憾的是,它在Safari中运行不佳,但在Firefox中运行良好。
对于跨浏览器体验,这个线程中的jQuery解决方案是最好的。
我会创建2个标题,1有背景,1没有。使用jQuery在两者之间渐变。可能会在所有浏览器上工作。
你可以传递多个属性到一个jQuery动画函数(http://api.jquery.com/animate/)。不确定是否可以动画渐变背景的不透明度?
相关文章:
- Google/html5语音识别JavaScript SDK Chrome网络工具包SpeechRecognition
- 如何在GoogleWeb工具包(GWT)中从JSNI调用接口(实例化)
- jQuery工具验证器自定义效果-添加&消除影响
- Jquery工具在Webkit中不起作用
- Javascript图形可视化工具包,具有高性能(500-1000个节点)
- 用于Javascript的Onelogin SAML工具包
- 如何在函数内部为jquery工具提示调用不同的var字符串
- Ajax控制工具包中的错误's升级后的JS文件
- 设计师如何使用GoogleWeb工具包
- Safari 5.1.7 flexslider/jquery工具冲突z索引错误
- Webpack和Dojo工具包
- AWS S3 JavaScript 开发工具包 getSignedUrl 仅返回基本路径
- 如何通过谷歌身份工具包修改登录按钮?(节点.js)
- 使用 jQuery 工具提示插件获取 clientX
- 相当于 Jquery/Backbone.js 中的 Dgrid/Store (Dojo 工具包)
- jQuery解包多个递归节点
- jquery与ajax控制工具包冲突2013年9月/10月发布
- 有没有一种方法来动画的悬停类在jquery中不使用插件/ui工具包
- jquery.js在Perl模板工具包生成的文件中没有正确引用
- 通过AJAX发布带有jquery工具包(jkit)验证的表单