离开悬停后如何将P标签保持在上一个位置
how to keep p tag on previous position after leave hover?
我想在离开悬停后将 p 标签保留在上一个位置,即 top:0px .我在 css 中将 top:0px 添加到 p 中,但不起作用。有什么建议吗?请帮忙。谢谢。下面是它的片段。
$(document).ready(function(){
$('.hexagon-in1').hover(function(){
$('.hexagon-in1 p').animate({
"top":"185px",
})
});
});
.hexagon-in1 p{
position: relative;
font-size: 25px;
color: #000;
text-align: center;
top: 0px ;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="hexagon hexagon-scale"><div class="hexagon-in1"><div class="hexagon-in2 red bgone"><p>Beach House</p></div></div></div>
没有"循环"问题的可能解决方案
$(document).ready(function(){
$('.hexagon-in1') .mouseover(function() {
$('.hexagon-in1 p').stop().animate({
"top":"185px",
});
})
.mouseout(function() {
$('.hexagon-in1 p').stop().animate({
"top":"0px",
});
});
});
.hexagon-in1 p{
position: relative;
font-size: 25px;
color: #000;
text-align: center;
top: 0px ;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="hexagon hexagon-scale"><div class="hexagon-in1"><div class="hexagon-in2 red bgone"><p>Beach House</p></div></div></div>
jQuery hover
接受两个参数,第一个回调用于悬停,第二个回调用于悬停。传递第二个参数并执行相反的操作。
$(document).ready(function(){
$('.hexagon-in1').hover(
function(){
$('.hexagon-in1 p').animate({
"top":"185px",
});
},
function(){
$('.hexagon-in1 p').animate({
"top":"0px",
});
);
});
$(document).ready(function(){
var position;
$('.hexagon-in1').hover(function(){
animate(185);
},
function(){
animate(0);
});
function animate(position){
$('.hexagon-in1 p').animate({
"top": position + "px",
});
}
});
.hexagon-in1 p{
position: relative;
font-size: 25px;
color: #000;
text-align: center;
top: 0px ;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="hexagon hexagon-scale"><div class="hexagon-in1"><div class="hexagon-in2 red bgone"><p>Beach House</p></div></div></div>
一旦触发jquery动画CSS就会应用并保留。此时,一旦您不悬停它,就需要覆盖它。
CSS 过渡非常容易做到这一点:
.hexagon-in1 p{
position: relative;
font-size: 25px;
color: #000;
text-align: center;
top: 0px ;
transition:0.5s;
}
.hexagon-in1:hover p {
top:185px;
}
<div class="hexagon hexagon-scale"><div class="hexagon-in1"><div class="hexagon-in2 red bgone"><p>Beach House</p></div></div></div>
不需要
jQuery man。您只能使用 css。
.hexagon-in1 p{
position: relative;
font-size: 25px;
color: #000;
text-align: center;
top: 0px ;
transition:.7s all;
}
.hexagon-in1:hover p{
top: 185px ;
}
<div class="hexagon hexagon-scale"><div class="hexagon-in1">
<div class="hexagon-in2 red bgone"><p>Beach House</p></div></div></div>
相关文章:
- 是否可以将一个元素还原为它's上一个位置,而不将该位置作为参数传递
- jquery scrolltop()返回上一个滚动位置的值
- 阻止浏览器在按下后退按钮时捕捉到上一个滚动位置
- 浏览器的“上一个”按钮位置更改
- 查找主干集合上的位置仅返回一个结果
- 用户在谷歌地图上标记一个位置
- 离开悬停后如何将P标签保持在上一个位置
- JQuery/Javascript:如何将一个东西放回页面加载上的位置
- 返回上一个滚动位置 - jquery移动页面设计
- 如何使用散列标签(“一个名字”)去页面上的位置,但在顶部说明一个固定的元素
- 确定拉斐尔路径上一个点的位置
- 如何在谷歌地图上绘制位置标记并在单击其中一个时显示详细信息
- 如何使用 jquery 获取下一个/上一个链接,无论它在 DOM 中的位置如何
- 如何在HTML5画布上获得鼠标的第一个和最后一个位置
- JS:如何找到一个元素在屏幕上的位置,而不会在不同的电脑上有所不同
- 我想使用谷歌地图上的位置,当我点击一个特定的按钮,我想去那个位置
- jQuery在dom上按位置隐藏下一个元素
- 在新页面上加载一个flash视频,它在上一页上的位置
- 使用锚点指向谷歌地图上的一个位置
- 在余弦曲线上找到与另一个位置有指定距离的位置