作业一:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>图片变色</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js">
</script>
<style>
img {
width: 200px;
height: 200px;
transition: filter 0.5s;
}
</style>
</head>
<body>
<img id="color-change" src="kitty.jpg" alt="Original Image">
<script>
$(document).ready(function(){
$("#color-change").click(function(){
$(this).attr("src", "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fb-ssl.duitang.com%2Fuploads%2Fitem%2F201810%2F06%2F20181006174836_PGHmM.jpeg&refer=http%3A%2F%2Fb-ssl.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1723865534&t=f53d7807a484a98bd174a33ac9eb6908g");
});
});
</script>
</body>
</html>
作业二:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>背景渐变</title>
<style>
body {
height: 100vh;
margin: 0;
display: flex;
justify-content: center;
align-items: center;
transition: background 0.5s;
}
</style>
</head>
<body>
<script>
let direction = "to right";
function changeGradientDirection() {
if (direction === "to right") {
document.body.style.background = "linear-gradient(to bottom, #00FFFF, #FF69B4)";
direction = "to bottom";
} else {
document.body.style.background = "linear-gradient(to right, #00FFFF, #FF69B4)";
direction = "to right";
}
}
document.body.addEventListener("click", changeGradientDirection);
</script>
</body>
</html>