【发布时间】:2014-04-29 13:12:28
【问题描述】:
如果您查看http://jsfiddle.net/MG4hw/2/,就会看到一个红色的菜单按钮。将鼠标悬停在它上面会显示一个绿色弹出菜单。问题在于,在滚动蓝色任务栏或粉红色内容时(它们彼此独立滚动),弹出菜单不会与按钮保持对齐。
(弹出菜单是绝对定位的,因为作为蓝色任务栏的相对子元素,它会被前者的溢出属性隐藏。)
我尝试了 .scroll() 和 .scrollTop()(参见代码 cmets),但没有成功。
如果没有其他可能性,至少我想在滚动时隐藏弹出菜单。
function positioning() {
$('#start').bind({
mouseenter: function () {
var startOffset = $(this).offset();
$('.start_options').css({
position: 'absolute',
top: startOffset.top, //+ $(document).scrollTop(), did not work
left: startOffset.left - $('.start_options').width()
});
$('.start_options').show();
},
mouseleave: function () {
$('.start_options').hide();
}
});
$('.start_options').bind({
mouseleave: function () {
$(this).hide();
},
mouseenter: function () {
$(this).show();
}
});
};
$(document).ready(positioning); //function call upon loading page
$(window).resize(positioning); //function call upon window resizing
//$(window).scroll(positioning); did not work either
任何帮助将不胜感激!
【问题讨论】:
标签: jquery scroll hover offset scrolltop