javascript - 在html中使用放大镜将鼠标悬停在图像上

标签 javascript php html

我使用以下说明在我的网页中为图像添加了一个放大镜: https://www.w3schools.com/howto/howto_js_image_magnifier_glass.asp

即使鼠标不在放大框上,放大框也会停留在图像上。我怎样才能修改为只有当鼠标悬停在放大镜上时才会出现放大镜?

谢谢,

最佳答案

您可以使用悬停在 CSS 中完成这一切,无需 javascript 从下面复制样式表。

<style>
* {box-sizing: border-box;}
.img-magnifier-container {
  position:relative;
  cursor:none;
}
.img-magnifier-container:hover .img-magnifier-glass {
  position: absolute;
  border: 3px solid #000;
  border-radius: 50%;
  cursor: none;
  /*Set the size of the magnifier glass:*/
  width: 100px;
  height: 100px;
  display:block;
}
.img-magnifier-glass {
  display:none;
}

</style>

关于javascript - 在html中使用放大镜将鼠标悬停在图像上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48757710/

相关文章:

javascript - 将数组转换为带有子对象的对象

Javascript:点击获取并在剪贴板上分配值

Javascript:如何检测浏览器窗口是否在 Android 设备底部滚动

php - 如何在没有表单的情况下传递变量

javascript - 如何防止点击 "Select all"复选框影响表头和列排序

javascript - Onchange 事件解决多个下拉菜单问题

php - 使用 urldecode() 导致 MySql 错误

php - 仅使用一次 $_POST 信息

javascript - jQuery 将新创建的字符串添加到 .css 中

javascript - 根据变量值选中复选框