mouseenter z-index 10 动画到左边,然后 mouseleave z-index -10 动画回到右边?
我试图始终将此隐藏的 div 放在主 div 后面,除非:
鼠标进入隐藏的 div,它应该向左动画,然后回到右侧并位于主 div 的顶部,
然后当鼠标离开时隐藏的 div,它向左动画,然后回到右侧,位于主 div 后面。
我不熟悉 js 和 jQuery,所以我尝试了类似的方法:
<div class="mainDiv">
content of main div
<div class="hiddenDiv">
content of hidden div
</div>
rest of content of main div
</div>
<script>
jQuery(document).ready(function() {
jQuery(".hiddenDiv")css('z-index',"-10");
//tell hiddenDiv to be hidden, this seem to block everything for some reason
jQuery(".hiddenDiv").mouseenter(function () {
jQuery(".hiddenDiv").animate({"left": "-=50px"}, "fast").css('z-index',"10");
//when mouse enters, hiddenDiv shows up
}),
jQuery(".hiddenDiv").mouseleave(function () {
jQuery(".hiddenDiv").animate({"left": "+=50px"}, "slow").css('z-index',"-10");
//when mouse leaves, it's hidden again.
});
});
</script>
但我发现当我在请求时给隐藏 div 的 z-index 为 -10 时,没有任何效果。 有人能指出我实现这一目标的正确方向吗?
I am trying to have this hidden div behind the main div at all times, exept when:
mouse enters the hidden div, it should animate to the left, then back to the right and be on top of the main div
then when mouse leave the hidden div, it animated to the left, and back to the right to be behind the main div.
I'm not familiar with js and jQuery, so I tried something like:
<div class="mainDiv">
content of main div
<div class="hiddenDiv">
content of hidden div
</div>
rest of content of main div
</div>
<script>
jQuery(document).ready(function() {
jQuery(".hiddenDiv")css('z-index',"-10");
//tell hiddenDiv to be hidden, this seem to block everything for some reason
jQuery(".hiddenDiv").mouseenter(function () {
jQuery(".hiddenDiv").animate({"left": "-=50px"}, "fast").css('z-index',"10");
//when mouse enters, hiddenDiv shows up
}),
jQuery(".hiddenDiv").mouseleave(function () {
jQuery(".hiddenDiv").animate({"left": "+=50px"}, "slow").css('z-index',"-10");
//when mouse leaves, it's hidden again.
});
});
</script>
But I see that when I give the hidden div a z-index of -10 at the begging, nothing works.
Could anyonde point me to the right direction to ahieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您遇到的第一个问题是,您的hiddendiv 无法滚动,它隐藏在您的-10 z 索引中。这意味着就您的选择器而言,它不在那里。
我会将您的第一个选择器更改为:
如果没有这个,您将无法使用您的hiddenDiv作为选择器
First first problem you're having is, your hiddendiv can't be rolled over, its hidden with your -10 z index. Meaning as far as your selector is concerned its not there.
I would change your first selector to:
WIthout this you can not use your hiddenDiv as a selector
应该写成
,你的第二个语句是错误的,因为缺少一个点
,所以尝试像这样写
should be written as
and your second statement is wrong, since a dot is missing
so try write like so instead
看看这个;
Have a look at this one;