我正在尝试构建一些在悬停时移动 DIV 框的悬停按钮。我为此使用鼠标悬停,但这只会使 DIV 框移动一次,而我希望它在按钮悬停时继续移动。
这可能吗?
这是代码:
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"> </script>
<title>jQuery tests</title>
<style type="text/css">
.div1{
position: absolute;
border-style: solid;
border-radius: 7px;
top:50px;
width: 75px;
height: 75px;
z-index: -1;
}
.but{
border-style: dashed;
padding: 2px;
margin:2px;
width: 50px;
text-align: center;
}
</style>
</head>
<body>
<div style="width:310; align:center;">
<div class="but" id="up">Up</div>
<div class="but" id="left" style="float:left;">Left</div>
<div class="but" id="right" style="float:left;">Right</div>
<div class="but" id="down">Down</div>
<div class="div1"></div>
</div>
<script>
$('#left').on('mouseover', function(){
$('.div1').animate({'left':'-=50'},100);
});
$('#right').on('mouseover', function(){
$('.div1').animate({'left':'+=50'},100);
});
$('#up').on('mouseover', function(){
$('.div1').animate({'top':'-=50'},100);
});
$('#down').on('mouseover', function(){
$('.div1').animate({'top':'+=50'},100);
});
</script>
</body>
</html>