- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在 github pages 上做一个元素,如果 div 的 overflow-y: scroll,我用
将导致下拉菜单被 chop/溢出。您可以在此 jsfiddle 看到该功能正常工作.请注意,如果您单击顶行右侧的省略号图标,它将下拉,如果您单击底行的图标,它将向上下拉。 .dropup
替换 Bootstrap .dropdown
现在,我的实际实现(github page),代码完全相同(如下),但它想用 .dropup
替换所有 .dropdown
类打开时,包括被切断的最顶行,如下图所示。 我已经为此苦苦挣扎了一个星期,但无法完全弄清楚。我已经尝试了一些不同的东西,我认为可以解决它,但最终只是一个 hack 并且不能在移动设备上工作,或者替换了一些但不是全部等。
这是我正在使用的 Javascript/jQuery,可以在 jsfiddle 和我的 github 源中看到 here .
$(document).on("shown.bs.dropdown", ".dropdown", function () {
// calculate the required sizes, spaces
var $ul = $(this).children(".dropdown-menu");
var $button = $(this).children(".song-menu");
var ulOffset = $ul.offset();
// how much space would be left on the top if the dropdown opened that direction
var spaceUp = (ulOffset.top - $button.height() - $ul.height()) - $('#playlist').scrollTop();
// how much space is left at the bottom
var spaceDown = $('#playlist').scrollTop() + $('#playlist').height() - ((ulOffset.top + 10) + $ul.height());
// switch to dropup only if there is no space at the bottom AND there is space at the top, or there isn't either but it would be still better fit
if (spaceDown < 0 && (spaceUp >= 0 || spaceUp > spaceDown))
$(this).addClass("dropup");
}).on("hidden.bs.dropdown", ".dropdown", function() {
// always reset after close
$(this).removeClass("dropup");
});
编辑:为了消除任何混淆,这里有一个没有我添加的 .dropup
函数的行为示例。 jsfiddle请注意,当您单击最后一个菜单项时,它会打开菜单但需要滚动。在这种情况下,我特别想删除 .dropdown
类并添加 .dropup
,因此不需要滚动。
最佳答案
这需要一些基本的数学知识,但我设法弄清楚了你想做什么。此代码根据可用于普通下拉菜单的空间更改下拉菜单和下拉菜单之间的 Bootstrap 类。
我通过减去按钮的高度、下拉菜单以及按钮在 scrollContainer 中从 scrollContainer 的高度向下滚动的距离来计算这一点。通过使用按钮偏移量并减去 scrollContainer 的偏移量,我得到了 div 向下滚动了多少的值。
这是我的 jQuery(我选择了 .playlist 类,因为它附加到您的 scrollContainer,但您应该用 id 替换它或通过其他方式选择它):
$(".dropdown, .dropup").click(function(){
var dropdownClassCheck = $(this).hasClass('dropdown');
var buttonOffset = $(this).offset().top;
var scrollboxOffset = $('.playlist').offset().top;
var buttonHeight = $(this).height();
var scrollBoxHeight = $('.playlist').height();
var dropDownButtonHeight = $(this).children('ul').height();
dropdownSpaceCheck = scrollBoxHeight>buttonOffset-scrollboxOffset+buttonHeight+dropDownButtonHeight;
if(dropdownClassCheck && !dropdownSpaceCheck){
$(this).removeClass('dropdown').addClass('dropup');
}
else if(!dropdownClassCheck && dropdownSpaceCheck){
$(this).removeClass('dropup').addClass('dropdown');
}
});
工作JSFiddle
如果有部分代码可以改进/更容易完成,或者我的解决方案是否有任何问题,请告诉我。
关于javascript - 用 Dropup 替换 Bootstrap Dropdown(两个几乎相同的实现的不同事件),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40122196/
我正在用 C 写一个高级计算器。正如你所猜到的,它目前有很多函数,我使用一个开关来对每个函数名进行适当的操作。它是这样的: switch(hash_of(function_name_currently
在大约四天的时间里,我一直在收集托管应用程序的性能计数器。在此期间,发生了以下垃圾回收: 第 0 代:133,695 第一代:133,413 第 2 代:133,254 其中一些是使用GC.Colle
我构建了这个: [ Workshop_templates 表 ] id_template | Workshop_name 1 | Conflict resolution 2 | Building tr
我有一个 N 的列表元素,我想抽样 M ( N/2 . IE。当超过一半的值被采样时。但它非常适合 M N/2 时反转问题。 : 注意:这实际上是创建一个大小为 N 的屏蔽列表对于 M 是 Fals
伙计们,我是竞争性编程的新手,我遇到了一个小问题在提供输入的同时在问题中,顶点数从 1 到 n但是我编写程序时考虑到节点是从 0 开始的 但是当我通过从每个边的每个顶点减少 1 来输入测试用例时,我的
在一次旅行中,有多个停靠点,(一个停靠点 = 一个或多个订单加载或交付的地址),按特定顺序排列。 例如: Trip A Trip_order Action Place Ord
我有一个关于由微服务组成的应用程序架构的问题。 我的微服务很少,但在这个问题的上下文中有趣的是: 人力资源 - 这里存储了所有用户数据,如用户名、性别、用户体验等。 工作机会 - 这里存储了每个招聘广
假设我的工作空间(全局环境)中有许多对象,并且我想将大多数对象存储在列表中。这是一个简化的示例: # Put some objects in the workspace A <- 1 B <- 2 C
当我获得与本地时间相同的时间戳时,firebase 生成的服务器时间戳是否会自动转换为本地时间,或者我错过了什么? _firestore.collection("9213903123").docume
我需要帮助才能将未知整数分成给定数量的偶数部分——或者至少尽可能地均匀。各部分之和应为原值,但各部分应为整数,且应尽可能接近。 参数 num: Integer - 应该被分成相等部分的数字 parts
我的 Java 程序中有一个带有 JPanel 的 ScrollPane,它附加了大量文本。我需要 ScrollPane 在每次添加后滚动到最底部。我对以下代码的问题是它“几乎”滚动到底部但不是一直滚
我想检查两个稀疏数组是否(几乎)相等。而对于 numpy 数组,你可以这样做: import numpy as np a = np.ones(200) np.testing.assert_array_
我有以下一组几乎相同的 each 语句。我需要添加大约 20 个遵循类似模式的内容。我正在尝试找出如何获取小变量并将它们更新为单个语句(而不是 20 次相同但略有不同的内容)。 $.each(main
所以我想获取两个字典中(几乎)匹配的键的值并将它们连接起来。我尝试过: dict3 = {key:dict1[key].strip() for key in dict2.keys() if key.p
我的表看起来像这样: | id (int) | sentence (varchar) | 我想找到除了一个特定单词之外几乎相同的所有行。例如: | 230 | test | | 321 | test
起始情况:MS SQL 中有一个现有的数据库模式,它与 MySQL 中的现有模式完全相同(数据库优先 - 无法更改,因为已广泛安装)。但是,它们在用于相应列的数据类型方面可能略有不同。该数据库系统必须
对于复杂的元素,一个很好的做法是(几乎)总是在闭包中定义 Polymer 以保持所有只应在内部修改的变量和方法私有(private),而不是将它们附加到元素(例如 'this ')? 喜欢以下内容:
我正在解析 Java 中的 RestAssured 调用,该调用返回对象列表。如果我使用此代码,Idea 会生成未经检查的分配警告: List availableInventories = ListP
我真的被难住了。我所拥有的是一个样式化为矩形的 div,其中包含作为页面主要标题的文本。相关代码如下: HTML: SIN CSS: h1 { text-align:right
我需要将单选按钮及其旁边的文本包装在标签中,只是为了更加用户友好。 几天前我遇到了类似的问题,我有一个复选框,并且在我有一个 span 元素之后立即出现。我可以包装这两个元素。 我有这个 HTML:
我是一名优秀的程序员,十分优秀!