jquery switchClass转换-背景图像
我对switchClass方法有一些问题。 当鼠标悬停在类上时,我想添加/删除css类(jquery switchClass转换-背景图像,jquery,background,jquery-animate,css-transitions,toggleclass,Jquery,Background,Jquery Animate,Css Transitions,Toggleclass,我对switchClass方法有一些问题。 当鼠标悬停在类上时,我想添加/删除css类(newsHover),并进行一些转换 我有以下代码 $('.newsArea').mouseover(function(){ $(this).switchClass('','newsHover',500, 'linear'); }).mouseleave(function(){ $(this).switchClass('newsHover','',500); }); 我认为
newsHover
),并进行一些转换
我有以下代码
$('.newsArea').mouseover(function(){
$(this).switchClass('','newsHover',500, 'linear');
}).mouseleave(function(){
$(this).switchClass('newsHover','',500);
});
我认为这些方法是正确的,正如你所看到的:
及
newsHover类有一个背景图像:
.newsHover{
background-image: url("../../images/newsArea-hover.png");
background-repeat: no-repeat;
background-position:left top;
width: 200px; height: 52px;
}
图像显示,但没有任何过渡。它出现在500毫秒之后
我可以接受css3跨浏览器的任何解决方案
有什么建议吗
谢谢
编辑
我忘了告诉你我正在使用1.7.2 jquery版本;jquery.easing.1.3和jquery-ui-1.8.23.custom.min(选择所有组件)有一个初始类,可以与-
$('.newsArea').mouseover(function(){
$(this).switchClass('oldClass','newsHover', 500);
}).mouseleave(function(){
$(this).switchClass('newsHover','oldClass',500);
});
也许在应用图像后加载图像需要时间
所以你可以试试
.oldClass{
background-image: url("../../images/newsArea-hover.png");
background-size:0px;
}
.newsHover{
background-size: auto;
}
仅供参考,您描述的行为完全符合预期。
switchClass
函数只是更改在“转换”结束时无法设置动画的属性<代码>开关类不支持设置背景图像的动画
并非所有样式都可以设置动画。例如,没有办法
设置背景图像的动画。任何无法设置动画的样式都将被删除
在动画结束时更改
从[http://api.jqueryui.com/switchClass/][1] 谢谢。但是addClass()和removeClass方法我不能有任何转换,对吗??还是我忘了什么?第一段代码不起作用。如果你能分析我给你的第二个链接的源代码,你可以看到类似的东西。关于第二个块,我没有尝试,但我想它会改变.newsrea类中文本的不透明度。所以这不是一个解决方案。Thanks@user794035例如我怀疑是这样。我删除了
不透明度
位是因为另一个原因,我认为这可能会导致您的图像加载耗时?无论如何,谢谢。同时,如果你有任何其他想法,请随意分享。