我在wordpress页面上实现了以下代码。
* {
margin: 0;
padding: 0;
}
.parent {
width: 100%;
margin: 10px auto;
position: relative;
}
.child {
position: absolute;
top: 0;
width: 100%;
height: 100%;
display: block;
overflow: hidden;
}
.parent:hover .child {
display: none;
}
p {
padding: 1em;
}
<div class="parent">
<img src="http://www.fundraising123.org/files/u16/bigstock-Test-word-on-white-keyboard-27134336.jpg" alt="" width="500px" height="auto" />
<div class="child">
<img src="http://maui.hawaii.edu/tlc/wp-content/uploads/sites/53/2013/11/testing.jpg" alt="" width="500px" height="auto" />
</div>
</div>
我有兴趣对其进行一些更改:
答案 0 :(得分:1)
你可以使用JavaScript来监听鼠标输入和CSS转换:
var shown = true;
var parent = document.querySelector('.parent');
var child = document.querySelector('.child');
parent.addEventListener('mouseenter', function(){
child.style.opacity = shown ? 0 : 1;
shown = !shown;
});
* {
margin: 0;
padding: 0;
}
.parent {
width: 100%;
margin: 10px auto;
position: relative;
}
.child {
position: absolute;
top: 0;
width: 100%;
height: 100%;
display: block;
overflow: hidden;
transition: opacity 0.5s linear;
}
p {
padding: 1em;
}
<div class="parent">
<img src="http://www.fundraising123.org/files/u16/bigstock-Test-word-on-white-keyboard-27134336.jpg" alt="" width="500px" height="auto" />
<div class="child">
<img src="http://maui.hawaii.edu/tlc/wp-content/uploads/sites/53/2013/11/testing.jpg" alt="" width="500px" height="auto" />
</div>
</div>