我試圖在頁面加載時更改網頁的背景顏色。我看不出爲什麼這不應該起作用,「身體」是我想操縱的正確元素。我使用http://docs.jquery.com/UI/Effects/animate作爲參考。jquery在頁面加載動畫頁面背景顏色
$(document).ready(function(){
$("body").animate({ backgroundColor: "#000000" }, 1000);
});
我試圖在頁面加載時更改網頁的背景顏色。我看不出爲什麼這不應該起作用,「身體」是我想操縱的正確元素。我使用http://docs.jquery.com/UI/Effects/animate作爲參考。jquery在頁面加載動畫頁面背景顏色
$(document).ready(function(){
$("body").animate({ backgroundColor: "#000000" }, 1000);
});
工作演示http://jsfiddle.net/aqrvA/8/
加入jQuery用戶界面庫,以及請大家會像火箭! <您的代碼是罰款>
jQuery UI的鏈接:http://jqueryui.com/
希望這有助於:)
腳本:
<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.8.18/jquery-ui.min.js"></script>
代碼
$(document).ready(function(){
$("html body").animate({ backgroundColor: "#000000" }, 1000);
});
使用只 jQuery的你不能動畫的色彩。您必須使用jQuery UI,將動畫擴展爲顏色。 Look here :)
「jQuery UI效果核心擴展了動畫功能,以便能夠生成動畫顏色。這些轉變可以動畫背景 和邊框顏色和接受的顏色在十六進制,RGB和顏色指定 名稱「。
,直到您裝入jquery-ui.js
https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.js
您將無法使用動畫功能這就是你所需要的。
謝謝你,很好。 – johnsonwi
@johnsonwi:確保接受解決你的問題的答案。 – Nope
@FrançoisWahl感謝你的精彩:) @ johnsonwi很高興能幫到你! –