简体   繁体   English

jQuery-我可以为CSS属性设置动画吗? 特别是背景图片

[英]jQuery - Can I animate css properties? Background-image particularly

I know I can fade in and out divs and elements, but can I animate properties as well? 我知道我可以淡入和淡出div和元素,但是我也可以为属性设置动画吗? I thought about this just now when changing background-image property of a certain div. 我刚才在更改某个div的background-image属性时就想到了这一点。 And thought it'd be cool if the background image was faded in as well ;) 并且认为如果背景图像也淡入也很酷;)

Here's the code I'm using to replace background image. 这是我用来替换背景图像的代码。 But can it be animated? 但是可以动画吗?

var originalBG = $('#wrapper').css('background-image');
$('.bggallery_images img').hover(function () {
    var newBG = "url('" + $(this).attr('src');

    $('#wrapper').css('background-image', newBG);
}, function () {
    $('#wrapper').css('background-image', originalBG);
});

jQuery has the animate() method that does exactly that. jQuery的animate()方法可以做到这一点。

Check out the examples in the manual, they should show you everything you need. 查看手册中的示例,它们将为您显示所需的一切。

JQuery UI is a plug in that extends the animation function to animate color if that's what you're looking to do with the background. JQuery UI是一个插件,可以将动画功能扩展为动画颜色(如果您要对背景进行动画处理)。 Basically if JQuery doesn't do it, there's most likely a library that extends it to have that functionality. 基本上,如果JQuery不这样做,则很可能是一个将其扩展为具有该功能的库。

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

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