gpt4 book ai didi

html - 底层和顶层的CSS悬停触发器

转载 作者:太空宇宙 更新时间:2023-11-04 14:11:22 24 4
gpt4 key购买 nike

如何为两个图层制作 css 悬停过渡。我写了整个页面,以便您可以(复制/粘贴)从您的计算机桌面上试用它。我的作品有效,但是如果没有 javascript/jQuery 和纯 CSS 可以完成吗?我尝试使用 CSS pointer-events 并且能够转换顶层(#circleOuter)或底层(#circleInner)但不能转换两个层。为此,#circleOuter:hover 必须触发#circleInner。感谢您的帮助。

<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script>
$(document).ready(function(){
$("#circleOuter").hover(function(){
$("#circleInner").css("transform","rotate(180deg)");
$("#circleOuter").css("transform","rotate(-180deg)");
}, function(){
$("#circleInner").css("transform","rotate(0deg)");
$("#circleOuter").css("transform","rotate(0deg)");
});
});
</script>
<style>
#circleWrap
{
background:#ff0;
width:200px;
height:200px;
position:relative;
}

#circleInner
{
background:url(http://socalsky.com/_/images/mis/circle_inner.png) center center/ 188px 188px no-repeat;
width:200px;
height:200px;
position:absolute;
transform: rotate(0deg);
transition: 500ms ease all;
}

#circleOuter
{
background:url(http://socalsky.com/_/images/mis/circle_outer.png) center center/ 200px 200px no-repeat;
width:200px;
height:200px;
position:absolute;
transform: rotate(0deg);
transition: 500ms ease all;
}
</style>
</head>
<body>

<div id="circleWrap">
<div id="circleInner">
</div>
<div id="circleOuter">
</div>
</div>

</body>
</html>

最佳答案

根据您的实际示例,如果两个元素都是容器的大小并且同时触发只需使用父级触发它:

#circleWrap {
background: #ff0;
width: 200px;
height: 200px;
position: relative;
}

#circleInner {
background: url(http://socalsky.com/_/images/mis/circle_inner.png) center center/ 188px 188px no-repeat;
width: 200px;
height: 200px;
position: absolute;
transform: rotate(0deg);
transition: 500ms ease all;
}

#circleOuter {
background: url(http://socalsky.com/_/images/mis/circle_outer.png) center center/ 200px 200px no-repeat;
width: 200px;
height: 200px;
position: absolute;
transform: rotate(0deg);
transition: 500ms ease all;
}
#circleWrap:hover #circleInner{
transform: rotate(180deg);
}
#circleWrap:hover #circleOuter{
transform: rotate(-180deg);
}
<div id="circleWrap">
<div id="circleInner">
</div>
<div id="circleOuter">
</div>
</div>

关于html - 底层和顶层的CSS悬停触发器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43454920/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com