一张图片鼠标靠近后显示另一张图片,vscode怎么写,给个例子,有代码的。
vscode是个编辑器而已,是css怎么写吧
好家伙,搁着提需求呢
<!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>测试</title>
</head>
<body>
<div class="container">
<img class="img-1" src="https://i0.hdslb.com/bfs/banner/30297d8e6852032386a0c1cece5578717146e37e.png@976w_550h_1c.webp" alt="">
</div>
<script type="text/javascript">
var img_1 = document.querySelector('.img-1');
img_1.addEventListener('mouseover',function(){
this.src = 'https://i0.hdslb.com/bfs/banner/fa5dc38a18286c12eea5613244a5e8e8d76d0f4a.png@976w_550h_1c.webp';
});
img_1.addEventListener('mouseout',function(){
this.src = 'https://i0.hdslb.com/bfs/banner/30297d8e6852032386a0c1cece5578717146e37e.png@976w_550h_1c.webp';
});
</script>
</body>
</html>
一个div里面包裹一个img标签,给div设置一个背景图片,然后把img的移入效果hover设置为display:none