我正在尝试使用jQuery .animate()来改变一个div的背景,如果它向下滚动超过100个像素的页面。我包含了jQuery UI,所以这是没有问题的,以前我使用.css()的时候,代码是可以工作的。
JS:
$(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 (已工作):
$(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');
}
});发布于 2015-06-04 04:03:07
发布于 2015-06-04 03:54:48
背景、颜色和其他一些属性不能使用Jquery本身进行动画处理
仅可设置动画的属性属性:
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
发布于 2015-06-04 03:56:07
https://stackoverflow.com/questions/30629323
复制相似问题