作業:構建網站 - 知識準備 - jQuery插件 - 顏色插件

什麼是插件?

插件就是用來做擴展功能的
jQuery插件庫:http://www.jq22.com/

顏色插件

網址:https://www.bootcdn.cn/jquery-color/

animate動畫不會改變背景色,如果非要改,就要使用插件
下面的代碼試圖在移動時將方塊的背景色變爲綠色,但是失敗

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .div1{
            width:300px;
            height:300px;
            background-color:red;
            position:absolute;
            left:0;
        }
    </style>
</head>
<body>
    <input type="button" value="移動" id="lr">
    <div class="div1"></div>
</body>
</html>
<script src="../JQuery/jquery-1.12.4.js"></script>
<script>
    $(function(){
        $('#lr').click(function(){
            $('.div1').animate({
                left:800,
                width:50,
                height:50,
                backgroundColor:'green'
            },2000);
        });
    });
</script>

在這裏插入圖片描述

使用插件
在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章