jquery動態改變背景顏色外掛程式,jquery動態背景顏色
GETHUB
背景顏色用animate方法時時無法改變顏色的
所以要使用外掛程式進行補充。
使用方法:
<!DOCTYPE html><html><head><style>div { background-color: #bada55; width: 100px; border: 1px solid green;}</style><script src="http://code.jquery.com/jquery-1.11.1.min.js"></script><script src="jquery.color.min.js"></script></head><body><button id="go">Simple</button><button id="sat">Desaturate</button><div id="block">Hello!</div><script>jQuery("#go").click(function(){ jQuery("#block").animate({ backgroundColor: "#abcdef" }, 1500 );});jQuery("#sat").click(function(){ jQuery("#block").animate({ backgroundColor: jQuery.Color({ saturation: 0 }) }, 1500 );});</script></body></html>
使用jQuery怎做div的背景色動畫改變效果?
可下載一個jquery backgroundposition 外掛程式,支援背景動畫
jquery中使用類選擇題改變div背景色
$(".test").onclick = function(){
$(this).css({"background": "red"});
};
改為:
$(".test").click = function(){
$(this).css({"background-color": "red"});
};
jquery所有的事件綁定都沒有on這個關鍵字。
另外,jquery的事件綁定需要放到readyfunction中去。
具體來說
<head>
<script type="text/javascript" src="/js/jQuery.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$(".test").click(function() {
$(this).css({"background-color": "red"});
});
});
</script>
</head>
<body>
<div class="test"
style="background-color: gray; width: 300px; height: 200px;"></div>
</body>
</html>