一.使用Jquery完成点击图片变换图片颜色
1.代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>作业1</title>
<script src="../../0.4.html/10724a8a8b6c8445e18dcd3f113c7b38_cf27148cd43a0caaa5b64c894d5f78fb_8.js"></script>
<style>
.divclass{
width:400px;
height: 400px;
background-color: red;
margin: auto;
}
.divclassC{
width:400px;
height: 400px;
background-color: blue;
margin: auto;
}
</style>
</head>
<body>
<div id="divid" class="divclass"></div>
</body>
</html>
<script>
$("#divid").click(function(){
$(".divclass").attr('class','divclassC');
});
</script>
2.运行截图
>.点击前:
>.点击后:
二. 使用JS中的DOM操作完成背景颜色渐变方向变换。点击背景,渐变方向发生改变。
1.代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title背景颜色渐变</title>
<style>
div{
height: 800px;
}
body{
transition: background 3s;
}
</style>
</head>
<body>
<div></div>
</body>
</html>
<script>
let color = 1;
document.body.addEventListener('click', function() {
if (color == 1) {
document.body.style.backgroundColor = 'aquamarine';
color = -1;
} else {
document.body.style.backgroundColor = 'blue';
color = 1;
}
});
</script>
2.运行截图
>.点击前:
>.点击后: