[英]div colour not changing in .animate()
I am trying to change the colour of a div
randomly on each mouse click but its not changin colour: 我试图在每次单击鼠标时随机更改
div
的颜色,但不能更改颜色:
div.on('mousedown', function () {
var newColor = '#'+(0x1000000+(Math.random())*0xffffff).toString(16).substr(1,6);
points += 1;
div.animate({color: newColor}, 2000);
$('#total-points').text(points);
});
Through debugging I can confirm that newColour
has been set and animate()
has been called on the div
. 通过调试,我可以确认已设置
newColour
并在div
上调用了animate()
。
Also I have jQueryUI referenced to its script in the local project directory <script src="jQueryUI.js"></script>
另外,我在本地项目目录
<script src="jQueryUI.js"></script>
I suspect that it maybe something to do with the div's
css properties overriding but not too sure where to go from here. 我怀疑这可能与
div's
css属性覆盖有关,但并不太确定从这里到哪里。
Here is the JSFiddle that displays the problem 这是显示问题的JSFiddle
you need to use backgroundColor and not color in order to change the box background. 您需要使用backgroundColor而不是color来更改框背景。 also i loaded jquery and jquery UI scripts from CDN and not locally.
我也从CDN而不是本地加载了jquery和jquery UI脚本。
div.on('mousedown', function () {
var newColor = '#'+(0x1000000+(Math.random())*0xffffff).toString(16).substr(1,6);
points += 1;
div.animate({backgroundColor: newColor}, 2000);
$('#total-points').text(points);
});
I forked your JSFiddle scripts and created a new one. 我分叉了您的JSFiddle脚本并创建了一个新脚本。 You can find it in here
你可以在这里找到
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.