【发布时间】:2013-06-20 21:32:53
【问题描述】:
我正在尝试根据光标位置更改顶部和底部颜色的渐变。以下函数在使用$(document.body).css('background','rgb('+rgb.join(',')+')'); 更改背景时有效,但我似乎无法让它与渐变一起使用。下面的代码是我为在 Firefox 中测试而设置的。我将更新代码,同时我目前尝试为每个浏览器设置选项。
http://coreytegeler.com/justin/
$(window).load(function(){
var $win = $(window),
w = 0,h = 0,
top = [],
bottom = [],
getWidth = function() {
w = $win.width();
h = $win.height();
};
$win.resize(getWidth).mousemove(function(e) {
top = [
Math.round(e.pageX/w * 255),
Math.round(e.pageY/h * 255),
150
];
bottom = [
Math.round(e.pageX/h * 255),
Math.round(e.pageY/w * 255),
150
];
$(document.body).css('background: -moz-linear-gradient(top, ('+top.join(',')+'), ('+bottom.join(',')+'))');
}).resize();
});
【问题讨论】:
标签: javascript jquery gradient linear-gradients