
关于#javascript#的问题,请各位专家解答!需要代码和截图。本人没环境,所以完整一点就行,代码,截图是运行截图。

```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<style>
#Viewimg{
width:450px;
height:450px;
transition: all .05s;
}
</style>
<body>
<img id="Viewimg" src="../img/background.jpeg" />
<button onclick="setViewimg(true)" >放大</button>
<button onclick="setViewimg(false)">缩小</button>
<script>
let zoom=1;//默认缩放值
function setViewimg(state){
let Viewimg=document.getElementById('Viewimg');
if(state){
zoom+=0.1;
}else{
zoom-=0.1;
}
Viewimg.style=`transform: scale(${zoom});`
}
</script>
</body>
</html>
```