html - 当 HTML 和 CSS 在同一个编辑器页面中时,如何在鼠标悬停时放大图像
问题描述
我正在开发一个在同一页面中结合 HTML 和 CSS 的 HTLM 编辑器。我希望用户在将鼠标悬停在首页图片上时进行缩放
<h4><img style="border: 1px solid black; align: right;" title="" src="sys_attachment.do?sys_id=00ee33cbdb1b9c507261e03cd396190b" alt="" width="204" align="right" border="1" hspace="" vspace="" /></h4>
<h4><strong>4. Entrez votre mot de passe.</strong></h4>
<ul style="list-style-type: disc; list-style-position: inside;">
<li>Puis, cliquez sur "Suivant".</li>
</ul>
我搜索了解决方案,但解决方案总是将 HTML 和 CSS 分开如果有人有任何建议或解决方案,请帮助我!
对不起我的英语,我还在学习!
解决方案
这是一个使用 css 的完整示例:hover
。不需要JS。
您需要将style
元素设置为head
元素外的body
元素
<html>
<head>
<style>
.zoom {
transition: transform .2s; /* Animation */
}
.zoom:hover {
transform: scale(1.5); /* (150% zoom - Note: if the zoom is too large, it will go outside of the viewport) */
position:absolute;
right:0;
}
</style>
</head>
<body>
<p> </p>
<hr />
<h4 class="zoom"><img style="border: 1px solid black; align: right;" title="" src="https://cdn.pixabay.com/photo/2020/09/09/13/03/bike-riding-5557589_1280.png" alt="" width="204" align="right" border="1" hspace="" vspace="" /></h4>
<h4><strong>4. Entrez votre mot de passe.</strong></h4>
<ul style="list-style-type: disc; list-style-position: inside;">
<li>Puis, cliquez sur "Suivant".</li>
</ul>
<p> </p>
</body>
</html>
这是 JS Adapt 的解决方案,来自此处的答案:Javascript: Zoom in on mouseover WITHOUT Jquery or plugins
<html>
<head>
<style>
</style>
</head>
<body>
<p> </p>
<hr />
<h4>
<img id="imgZoom" style="border: 1px solid black; align: right;" width="200px" height="200px" align="right" onmousemove="zoomIn(event)" onmouseout="zoomOut()" src="https://cdn.pixabay.com/photo/2020/09/09/13/03/bike-riding-5557589_1280.png">
<div style="border: 1px solid black;
width: 200px;
height: 200px;
display: none;
background-image: url('https://cdn.pixabay.com/photo/2020/09/09/13/03/bike-riding-5557589_1280.png');
background-repeat: no-repeat;"
id="overlay"
onmousemove="zoomIn(event)"></div>
</h4>
<h4><strong>4. Entrez votre mot de passe.</strong></h4>
<ul style="list-style-type: disc; list-style-position: inside;">
<li>Puis, cliquez sur "Suivant".</li>
</ul>
<p> </p>
<script>
function zoomIn(event) {
var element = document.getElementById("overlay");
element.style.display = "inline-block";
var img = document.getElementById("imgZoom");
var posX = event.offsetX ? (event.offsetX) : event.pageX - img.offsetLeft;
var posY = event.offsetY ? (event.offsetY) : event.pageY - img.offsetTop;
element.style.backgroundPosition = (-posX * 4) + "px " + (-posY * 4) + "px";
}
function zoomOut() {
var element = document.getElementById("overlay");
element.style.display = "none";
}
</script>
</body>
</html>
直接在正文中的最后一个示例style
:它被正常接受https://www.w3.org/Submission/1996/1/WD-jsss-960822
<html>
<body>
<style>
.zoom {
transition: transform .2s; /* Animation */
}
.zoom:hover {
transform: scale(1.5); /* (150% zoom - Note: if the zoom is too large, it will go outside of the viewport) */
position:absolute;
right:0;
}
</style>
<p> </p>
<hr />
<h4 class="zoom"><img style="border: 1px solid black; align: right;" title="" src="https://cdn.pixabay.com/photo/2020/09/09/13/03/bike-riding-5557589_1280.png" alt="" width="204" align="right" border="1" hspace="" vspace="" /></h4>
<h4><strong>4. Entrez votre mot de passe.</strong></h4>
<ul style="list-style-type: disc; list-style-position: inside;">
<li>Puis, cliquez sur "Suivant".</li>
</ul>
<p> </p>
</body>
</html>
推荐阅读
- node.js - 快递服务器不会连接到端口
- python - 根据公共字符串将列表排序为列表,同时保留整个列表
- node.js - NODEJS - 即使成功完成,从另一个端点调用一个端点也会陷入 CATCH
- performance - 如何限制Julia中函数的位数
- iframe - 使用“Iframe”自定义 RSS 提要
- html - 有没有办法使用 Javascript 编写大块 HTML
- pull - 将请求拉入 master 将较早的提交显示为最近的提交
- java - Java Singleton 对象可以仅部分被垃圾收集吗?
- javascript - 通过共享道具值合并对象数组
- python - 构建 numpy 数组列表