css - 有没有办法定位 img 标签对象位置 x 和 y?
问题描述
我已经包含了我的 codepen 作为示例。我需要让图像随光标移动。是否有像 object-position Y 这样的属性或我可以使用的东西?
我知道我可以做背景位置 x 或 y ,但为什么不做对象位置 X 或 Y 呢?
const images = document.querySelectorAll('.image');
images.forEach((image) => image.addEventListener('mousemove', (e) => {
image.style.objectPosition = -e.offsetX + "px"<--works but I want both directions??
//image.style.objectPositionX = -e.offsetX + "px"//why cant i do these?
//image.style.objectPositionY = -e.offsetY + "px"
}));
解决方案
推荐阅读
- typescript - 如何动态地从 TypeScript 文件中导入常量?
- python - 如何在循环中创建页面,tkinter?
- android - 我正在尝试从我的 firebase 中检索数据,但不知何故,时间戳是以 java.util.data 格式接收的
- javascript - 从 html 代码中删除函数和属性
- r - 用 geom_sf 在 R 中绘制等值线图上的点
- swift - 从 Swift 中的 Firebase 登录身份验证中获取错误消息
- routes - TYPO3 如何处理自定义扩展的路由
- pandas - 如果第二个数据帧不存在,则取两个数据帧的差异,同时保留第一个数据帧的值
- python - Discord.py 如何让机器人在特定时间后删除消息
- css - 如何覆盖其他 CSS 样式?