jQuery 下滑面板
在我的网站上,我的顶部有一个面板,其中连续包含 9 个图像。在页面加载时,它是隐藏的,但它下面有一个选项卡,您可以看到 div 底部的 3 个像素。
我想要的是,当您将鼠标悬停在选项卡或面板的可见部分上时,框将向下滑动,然后当鼠标不再位于面板或选项卡上时,div 将向上滑动。我给选项卡和 div 都指定了“slider-handle”类。这就是 html 的样子:
<div id="slider-wrapper">
<div id="slider-content" class="slider-handle">
<img src="blabla.jpg" /> (*9)
</div>
<div id="slider-tab" class="slider-handle">
<span>Click here 2 open slider blabla.</span>
</div>
</div>
我想要的 jQuery 是这样的:
$(document).ready(function () {
$('.slider-handle').hover(function () {
$('slider-content').animate({
height: '50px'
});
}, function () {
$('slider-content').animate {
{
height: '3px'
});
});
});
如果只有一个元素具有 slider-handle 类,那么这将起作用,但是因为有 2 个,当您将鼠标悬停在一个元素之外并进入另一个元素时,它会起作用仍然将此事件视为“鼠标左滑块手柄元素”,并且存在闪烁现象。我希望这两个元素被视为一个元素,因为当您离开选项卡并输入滑块内容 div 时,不会触发悬停事件,因为鼠标尚未离开“滑块手柄”...如果那样有道理...
On my site I have a panel at the top containing like 9 images in a row. On page load it's hidden but there is a tab underneath it and you can see like 3 pixels of the bottom of the div.
What I want is that when you hover over the tab OR the visible part of the panel the box will slide down, and then when the mouse is no longer on the panel or the tab the div will slide up. I've given both the tab and the div a class of "slider-handle". This is what the html looks like:
<div id="slider-wrapper">
<div id="slider-content" class="slider-handle">
<img src="blabla.jpg" /> (*9)
</div>
<div id="slider-tab" class="slider-handle">
<span>Click here 2 open slider blabla.</span>
</div>
</div>
And what I want in the jQuery is something like this:
$(document).ready(function () {
$('.slider-handle').hover(function () {
$('slider-content').animate({
height: '50px'
});
}, function () {
$('slider-content').animate {
{
height: '3px'
});
});
});
Which would work if only one element had the slider-handle class, however because there's 2, when you hover out of one and into the other it still treats this event as 'mouse left slider-handle element' and there's like a flicker. I want these 2 elements to SORT OF be treated as ONE in that when you leave the tab and enter the slider-content div, the hoverout event isn't triggered because the mouse has not left 'slider-handle'...if that makes sense...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
slider-wrapper
div,如下所示:由于它包含两个元素,因此它们将被视为一个元素。
希望这有帮助。干杯
You can use your
slider-wrapper
div, like this:As it contains both elements, these will be treated as one.
Hope this helps. Cheers
您可以使用现有的 ID,并使用
#slider-wrapper
本身来触发“mouseleave”事件,因为它仍然会包裹选项卡和我使用的
click
内容打开选项卡,但您也可以使用mouseenter
例如
You can use the existing ID's, and use the
#slider-wrapper
itself to trigger the "mouseleave" event as it will still be wrapping the tab and the contentI used
click
to open tab but you can just as well usemouseenter
e.g.