Javascript 如何更改下拉框的位置?
我有一张下拉表。它出现在按钮悬停上。当它掉到窗口的不可见部分时,我试图让它掉到顶部,但我的功能不起作用 HTML: JS:Javascript 如何更改下拉框的位置?,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我有一张下拉表。它出现在按钮悬停上。当它掉到窗口的不可见部分时,我试图让它掉到顶部,但我的功能不起作用 HTML: JS: 我不太确定这是否是你想要实现的, 但这里是JS: function changePosition() { var currentForm = $(this).find('.popover-form'); if ( ($(this).offset().top + currentForm.height() ) > $(window).height() )
我不太确定这是否是你想要实现的, 但这里是JS:
function changePosition() {
var currentForm = $(this).find('.popover-form');
if ( ($(this).offset().top + currentForm.height() ) > $(window).height() ) {
currentForm.css('top', '-87px');
}
}
$('.main-btn').on('mouseover', changePosition);
还有小提琴:
编辑:我相信它的方式可能更符合你的需求。负面定位有点脏
function changePosition() {
var currentForm = $(this).find('.popover-form');
if ( ( $(this).offset().top + currentForm.height() ) > $(window).height() ) {
currentForm.css('bottom', $(this).offset().top );
currentForm.css('right', '0');
}
}
$('.main-btn').on('mouseover', changePosition);
小提琴:我不太确定这是否是你想要实现的, 但这里是JS:
function changePosition() {
var currentForm = $(this).find('.popover-form');
if ( ($(this).offset().top + currentForm.height() ) > $(window).height() ) {
currentForm.css('top', '-87px');
}
}
$('.main-btn').on('mouseover', changePosition);
还有小提琴:
编辑:我相信它的方式可能更符合你的需求。负面定位有点脏
function changePosition() {
var currentForm = $(this).find('.popover-form');
if ( ( $(this).offset().top + currentForm.height() ) > $(window).height() ) {
currentForm.css('bottom', $(this).offset().top );
currentForm.css('right', '0');
}
}
$('.main-btn').on('mouseover', changePosition);
小提琴:我不太确定这是否是你想要实现的, 但这里是JS:
function changePosition() {
var currentForm = $(this).find('.popover-form');
if ( ($(this).offset().top + currentForm.height() ) > $(window).height() ) {
currentForm.css('top', '-87px');
}
}
$('.main-btn').on('mouseover', changePosition);
还有小提琴:
编辑:我相信它的方式可能更符合你的需求。负面定位有点脏
function changePosition() {
var currentForm = $(this).find('.popover-form');
if ( ( $(this).offset().top + currentForm.height() ) > $(window).height() ) {
currentForm.css('bottom', $(this).offset().top );
currentForm.css('right', '0');
}
}
$('.main-btn').on('mouseover', changePosition);
小提琴:我不太确定这是否是你想要实现的, 但这里是JS:
function changePosition() {
var currentForm = $(this).find('.popover-form');
if ( ($(this).offset().top + currentForm.height() ) > $(window).height() ) {
currentForm.css('top', '-87px');
}
}
$('.main-btn').on('mouseover', changePosition);
还有小提琴:
编辑:我相信它的方式可能更符合你的需求。负面定位有点脏
function changePosition() {
var currentForm = $(this).find('.popover-form');
if ( ( $(this).offset().top + currentForm.height() ) > $(window).height() ) {
currentForm.css('bottom', $(this).offset().top );
currentForm.css('right', '0');
}
}
$('.main-btn').on('mouseover', changePosition);
小提琴:使用下面的代码。将css函数中的
bottom,87px
更改为top,$(this).offset().top
function changePosition() {
var currentForm = $(this).find('.popover-form');
var position = ( $(this).offset().top - currentForm.height() );
if ( position <= 0 ) {
currentForm.css('top', ($(this).offset().top + 10) );
currentForm.css('right', '0');
}else{
currentForm.css('bottom', ($(this).offset().top - (position + 10)));
currentForm.css('right', '0');
}
}
$('.main-btn').on('mouseover', changePosition);
要查看底部的菜单,只需从html中删除所有
标记。使用下面的代码。将css函数中的bottom,87px
更改为top,$(this).offset().top
function changePosition() {
var currentForm = $(this).find('.popover-form');
var position = ( $(this).offset().top - currentForm.height() );
if ( position <= 0 ) {
currentForm.css('top', ($(this).offset().top + 10) );
currentForm.css('right', '0');
}else{
currentForm.css('bottom', ($(this).offset().top - (position + 10)));
currentForm.css('right', '0');
}
}
$('.main-btn').on('mouseover', changePosition);
要查看底部的菜单,只需从html中删除所有
标记。使用下面的代码。将css函数中的bottom,87px
更改为top,$(this).offset().top
function changePosition() {
var currentForm = $(this).find('.popover-form');
var position = ( $(this).offset().top - currentForm.height() );
if ( position <= 0 ) {
currentForm.css('top', ($(this).offset().top + 10) );
currentForm.css('right', '0');
}else{
currentForm.css('bottom', ($(this).offset().top - (position + 10)));
currentForm.css('right', '0');
}
}
$('.main-btn').on('mouseover', changePosition);
要查看底部的菜单,只需从html中删除所有
标记。使用下面的代码。将css函数中的bottom,87px
更改为top,$(this).offset().top
function changePosition() {
var currentForm = $(this).find('.popover-form');
var position = ( $(this).offset().top - currentForm.height() );
if ( position <= 0 ) {
currentForm.css('top', ($(this).offset().top + 10) );
currentForm.css('right', '0');
}else{
currentForm.css('bottom', ($(this).offset().top - (position + 10)));
currentForm.css('right', '0');
}
}
$('.main-btn').on('mouseover', changePosition);
要查看底部的菜单,只需从html中删除所有
标记。此.offset().top
需要是$(此).offset().top
('onmouseover'
)需要是刚刚('mouseover'
)此.offset().top
需要是$(此).offset().top
('onmouseover'
)需要是公正的('mouseover'
)this.offset().top
需要是$(this.offset().top
('onmouseover'
)需要是公正的('mouseover'
)this.offset().top
需要是$(this.offset().top
('onmouseover'
)需要是公正的('mouseover'
)我无法删除top:87px
,因为它显示相对于父按钮的位置(87px是按钮的高度)。但无论如何,我尝试了这个变体,但它不起作用:现在窗体总是显示在顶部,而从不显示在底部。我不明白您到底想要什么?我希望在窗体不在窗口中时,将此窗体显示在按钮的顶部。当它在窗口中完全可见时,没有任何变化(显示在底部)--我无法删除top:87px
,因为它显示相对于父按钮的位置(87px是按钮的高度)。但无论如何,我尝试了这个变体,但它不起作用:现在窗体总是显示在顶部,而从不显示在底部。我不明白您到底想要什么?我希望在窗体不在窗口中时,将此窗体显示在按钮的顶部。当它在窗口中完全可见时,没有任何变化(显示在底部)--我无法删除top:87px
,因为它显示相对于父按钮的位置(87px是按钮的高度)。但无论如何,我尝试了这个变体,但它不起作用:现在窗体总是显示在顶部,而从不显示在底部。我不明白您到底想要什么?我希望在窗体不在窗口中时,将此窗体显示在按钮的顶部。当它在窗口中完全可见时,没有任何变化(显示在底部)--我无法删除top:87px
,因为它显示相对于父按钮的位置(87px是按钮的高度)。但无论如何,我尝试了这个变体,但它不起作用:现在窗体总是显示在顶部,而从不显示在底部。我不明白您到底想要什么?我希望在窗体不在窗口中时,将此窗体显示在按钮的顶部。当它在窗口中完全可见时,不会发生任何变化(显示在底部)----