简体   繁体   English

背景图片上的css3过渡在Firefox中不起作用

[英]css3 transition on background image doesn't work in Firefox

This is a follow up to my question here: jquery UI add class with animation does't work 这是我这里的问题的跟进: jQuery UI带有动画的添加类不起作用

See the new jsfiddle and try this in Firefox: http://jsfiddle.net/40mga4vy/3/ 请参阅新的jsfiddle,并在Firefox中进行尝试: http : //jsfiddle.net/40mga4vy/3/

-webkit-transition: all 2.0s ease;
-moz-transition: all 2.0s ease;
-o-transition: all 2.0s ease;
transition: all 2.0s ease;

This code in combination with some jquery animates a background image change when selecting a new background image from a select-element. 当从选择元素中选择新的背景图像时,此代码与一些jquery结合在一起可以使背景图像发生变化。 It works in all browsers except Firefox (tested in MacOS 35.0.1). 它适用于除Firefox(已在MacOS 35.0.1中测试)以外的所有浏览器。

While animating a change in the background color and width/height properties works like a charme in FF: http://jsfiddle.net/tw16/JfK6N/ - animating a background image does not work. 对背景颜色和宽度/高度属性进行动画处理时,就像在FF中使用超级按钮一样: http : //jsfiddle.net/tw16/JfK6N/-对背景图像进行动画处理不起作用。

Researching showed that a "left" property has to be set but it turned out to not have any impact. 研究表明,必须设置“左”属性,但结果没有任何影响。 I also tried various notations but with no success, I cannot make it work. 我还尝试了各种表示法,但没有成功,我无法使其正常运行。

There is a workaround shown in this fiddle: http://jsfiddle.net/40mga4vy/1/ 此小提琴中显示了一种解决方法: http : //jsfiddle.net/40mga4vy/1/

function changeBackground() {
    $('#wallpaper').removeClass();

    $("#wallpaper").addClass("wallpaper_" +      $("#select_category").val()).css('opacity','0').animate({opacity:'1'});
};

This works in FF but its a bit ugly as the class is removed and then opacity raises afterwards (doesn't look as smooth as the css solution). 这在FF中有效,但是由于删除了类,然后在之后不透明性提高时看起来有点难看(看起来不像CSS解决方案那样平滑)。

Any hints/tricks or is this simply not supported? 是否有任何提示/技巧?

As far as I know, there is no suport in any browser to swap images smoothly in one single element in css. 据我所知,在任何浏览器中都没有支持在CSS的单个元素中平滑交换图像的支持。 After you do what you need, make sure you take a look into performance, your workaround is not as much as efficient as it could. 在完成所需的工作之后,请确保对性能进行了研究,但解决方法却没有效率那么高。 In this code 在这段代码中

$("#wallpaper").addClass("wallpaper_" + $("#select_category").val()).css('opacity','0').animate({opacity:'1'}); $("#wallpaper").addClass("wallpaper_" + $("#select_category").val()).css('opacity','0').animate({opacity:'1'}); $("#wallpaper").addClass("wallpaper_" + $("#select_category").val()).css('opacity','0').animate({opacity:'1'}); ,

the browser will take every single step until 浏览器将采取每一个步骤,直到
.animate({opacity:'1'}) . .animate({opacity:'1'})
For instance, the browser first has to find $("#wallpaper") then, it will call for .addClass("wallpaper_" + ...); 例如,浏览器首先必须找到$("#wallpaper")然后它将调用.addClass("wallpaper_" + ...);
and concatenate the result from finding $("#select_category") then getting .val() and so on. 并从找到$("#select_category")然后得到.val()等结果连接起来。 everytime this function is called, it will iterate through every single of these objects, so it is not as efficient as probably could and with two more animations in the page, it may became a bit laggy, if possible, use animations through CSS. 每次调用此函数时,它都会遍历这些对象中的每个对象,因此它的效率可能不尽如人意,并且页面中还有两个动画,如果可能的话,使用CSS动画可能会有点麻烦。

Anyway, what I sugest you to do is (if i'm right about what you want), just do what's in here https://jsfiddle.net/bmjg5g9s/ 无论如何,我建议您做的是(如果我对您想要的东西是正确的),只需执行此处的内容https://jsfiddle.net/bmjg5g9s/

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

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