请查看我正在使用的 JSFiddle:http: //jsfiddle.net/txdwg/2/
HTML:
<a href="#">Hover here</a>
<div>Show me now!</div>
CSS:
div {
display:none;
width:100px;
height:100px;
background:red;
margin:20px;
}
a {
font-size:16px;
font-weight:bold;
}
JS:
(function($){
$.fn.hoverDelay = function(over, out, ms){
var delay, ms, that;
ms = ms || 500;
that = this;
that.bind('mouseenter.hoverDelay', function(e){
delay = setTimeout(function(){
over.call(that, e);
}, ms);
}).bind('mouseleave.hoverDelay', function(e){
clearTimeout(delay);
out.call(that, e);
});
};
})(jQuery);
$(function(){
$('a').hoverDelay(function(){
$('div').fadeIn(300);
}, function(){
$('div').fadeOut(300);
}, 300);
});
但是我想通过 CSS3 来代替 JS。我怎样才能仍然使用悬停伪选择器并拥有类似的动画?