经过几小时的摆弄和a little help from some friends我能够想出比以前更好的解决方案。该方法涉及在从扩展到width:10000px; height:10000px;
的悬停元素之前使用透明元素,并触发与画廊相同的悬停事件以显示next
元素。无论鼠标位于页面上何处,只有在动画完成后,才会使用此方法显示next
。
Updated Demo Here
body { overflow:hidden; }
#hoverHelper {
width:0px;
height:0px;
z-index:1;
position:absolute;
margin-top:-1000px;
margin-left:-1000px;
animation: hhAnimation .001s 3s forwards;
}
#actualHover {
width:50px;
height:50px;
background:teal;
animation: yourAnimation 3s linear forwards;
}
#next {
z-index:2;
position:relative;
display: none;
}
#actualHover:hover ~ #next, #hoverHelper:hover ~ #next, #next:hover {
display:inline-block;
}
@keyframes yourAnimation {
0% { background:teal; }
100% { background: red; }
}
@keyframes hhAnimation {
0% { width:0px;
height:0px;
}
100% { width:10000px;
height:10000px;
}
}
和HTML(只需确保#next
是别人后)
<div id='actualHover'></div>
<div id='hoverHelper'></div>
<a id='next'>Next</a>
我还添加了一些JavaScript,使它能够重复,并且告诉你怎么可能访问
解决方案应该是完全跨浏览器。唯一的负面影响是身体上的overflow:hidden
,可以通过使用javascript确定当前的窗口高度/宽度并将其设置为(包括调整大小)或类似的东西来进一步优化
请发布您的代码。 – j08691
重复? http://stackoverflow.com/questions/11074815/jquery-trigger-hover-on-anchor – pbenard
您是否在寻找[this](http://stackoverflow.com/questions/6222724/send-hover-event-programmatically) ? – Harry