【发布时间】:2015-11-08 07:53:41
【问题描述】:
在上一个问题中,我问过如何制作“光标镜像”,这意味着如果您的光标要在网站顶部四处移动,则光标的单独反转图像将在网站的底部。链接到问题here。
继续这段代码,如果上半部分的实际光标悬停在 div 上使其消失(使用 CSS 悬停状态),镜像光标如何在不使用 .mouseover 事件的情况下使用 Javascript 实现相同的效果(因为它不是鼠标而是放置的图像)?对不起,如果标题含糊不清,但问题很难描述!
var $img = $('#mirror-image');
var imgHeight = $img.height() / 2;
function placeCursor(x, y){
$img.css({top: y + 'px', left: x+ 'px', position:'absolute'});
}
$(".top-half-black").mousemove(function(event){
var newY = $(this).height() - event.pageY - imgHeight;
placeCursor(event.pageX, newY);
});
body{
margin:0px 0px 0px 0px;
}
.top-half-black{
background-color:black;
width:100%;
height:50%;
}
.bottom-half-white{
position: relative;
}
#mirror-image{
left: 0;
top: 0;
position: absolute;
width: 17px;
height: 25px;
}
.rightside-up{
font-family:Arial;
font-size:36px;
color:white;
}
.rightside-up:hover{
opacity:0;
}
.upside-down{
font-family:Arial;
font-size:36px;
-webkit-transform: scaleY(-1);
-moz-transform: scaleY(-1);
-ms-transform: scaleY(-1);
-o-transform: scaleY(-1);
transform: scaleY(-1);
}
<div class="top-half-black">
<div class="rightside-up">Blah blah blah</div>
</div>
<div class="bottom-half-white">
<img id="mirror-image" src="http://i.imgur.com/cjjNbk1.png" />
<div class="upside-down"> Blah blah blah</div>
</div>
【问题讨论】:
标签: javascript jquery html css mouseover