首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >jquery animate()不能处理css属性

问jquery animate()不能处理css属性
EN

Stack Overflow用户
提问于 2015-06-04 03:48:17
回答 5查看 134关注 0票数 0

我正在尝试使用jQuery .animate()来改变一个div的背景,如果它向下滚动超过100个像素的页面。我包含了jQuery UI,所以这是没有问题的,以前我使用.css()的时候,代码是可以工作的。

JS:

代码语言:javascript
复制
$(window).scroll(function () {
    if ($(this).scrollTop() > 100) {
        $('#top-links-bar').stop().animate({ 'background' : 'linear-gradient(white, gray)' }, 500);
    } else {
        $('#top-links-bar').stop().animate({ 'background' : 'none' });
    }
});

较早的JS (已工作):

代码语言:javascript
复制
$(window).scroll(function () {
    if ($(this).scrollTop() > 100) {
        $('#top-links-bar').stop().css('background','linear-gradient(white, gray)');
    } else {
        $('#top-links-bar').stop().css('background','none');
    }
});

Fiddle

EN

回答 5

Stack Overflow用户

发布于 2015-06-04 04:03:07

你不能为background添加动画,但你应该能够使用jQuery颜色插件来制作background-color动画,该插件与jQuery UI捆绑在一起(请参阅here)。

然而,我不认为你可以动画渐变。

查看jquery Color here的文档,它看起来只接受十六进制(#000)、rgba (rgba(0, 0, 0, 0))和一些名称值(black)。

票数 1
EN

Stack Overflow用户

发布于 2015-06-04 03:54:48

背景、颜色和其他一些属性不能使用Jquery本身进行动画处理

仅可设置动画的属性属性:

代码语言:javascript
复制
backgroundPositionX
backgroundPositionY
borderWidth
borderBottomWidth
borderLeftWidth
borderRightWidth
borderTopWidth
borderSpacing
margin
marginBottom
marginLeft
marginRight
marginTop
outlineWidth
padding
paddingBottom
paddingLeft
paddingRight
paddingTop
height
width
maxHeight
maxWidth
minHeight
minWidth
fontSize
bottom
left
right
top
letterSpacing
wordSpacing
lineHeight
textIndent

阅读有关动画的更多信息以及可以为哪些属性设置动画的here

票数 0
EN

Stack Overflow用户

发布于 2015-06-04 03:56:07

不能对background进行动画处理,因为它不是动画属性。

查看可以通过css 动画的属性列表

http://www.w3schools.com/jquery/eff_animate.asp

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30629323

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档