<!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>
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, #ffcccc, #cc99ff)";
direction = "to bottom";
} else {
document.body.style.background = "linear-gradient(to right, #ffcccc, #cc99ff)";
direction = "to right";
}
}
document.body.addEventListener("click", changeGradientDirection);
</script>
</body>
</html>
初始图片
点击后