- objective-c - iOS 5 : Can you override UIAppearance customisations in specific classes?
- iphone - 如何将 CGFontRef 转换为 UIFont?
- ios - 以编程方式关闭标记的信息窗口 google maps iOS
- ios - Xcode 5 - 尝试验证存档时出现 "No application records were found"
我目前正在尝试制作垂直时间轴(就像在stackoverflow开发人员故事中一样)。
要求如下:
.timeline {
width: 100%;
}
.timeline-item {
box-sizing: border-box;
width: 50%;
position: relative;
float: left;
clear: left;
padding-left: 20px;
margin: 1px 0 1px;
background: tomato;
}
.timeline-item.inverse {
float: right;
clear: right;
background: grey;
}
/* Just used to show the middle point alignment */
.timeline-item::after {
content: '';
height: 2px;
width: 10px;
background: DarkGrey;
position: absolute;
top: 50%;
right: 0;
}
.timeline-item.inverse::after {
left: 0;
background: DarkRed;
}
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://code.jquery.com/jquery-1.11.1.min.js" type="text/javascript" ></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js" type="text/javascript" ></script>
<div class="timeline">
<div class="timeline-item">
<p>
1 This is some sample text (multiline)
<br>This is some sample text
<br>This is some sample text
<br>This is some sample text
<br>This is some sample text
<br>This is some sample text
<br>This is some sample text
<br>This is some sample text
<br>This is some sample text
</p>
</div>
<div class="timeline-item inverse">
<p>
2 This is some sample text
</p>
</div>
<div class="timeline-item inverse">
<p>
3 This is some sample text
</p>
</div>
<div class="timeline-item">
<p>
4 This is some sample text
</p>
</div>
</div>
最佳答案
目前无法使用普通CSS。但是,可以使用JavaScript来完成。
随意跳到底部进行演示,或继续阅读以获取详细说明。
方法。 我建议的解决方案如下。
•时间线上的事件绝对位于时间线容器内。
•JavaScript确定事件在时间轴上的位置,最后确定时间轴容器的高度。使用内联样式和一个类指示事件是在时间线的左侧还是右侧设置的。例如,该类可用于添加箭头。
•CSS确定事件和时间线的大小和外观。
要求。 问题提出以下要求。
R1时间线不应只左右改变事件。
R2如果需要,左右事件应填充剩余空间。
R3。项目的顺序应与提供的DOM结构中的顺序相同。
定位算法。 事件按照在DOM(R3)中出现的顺序在时间轴上从上到下定位。该算法跟踪每边的最后一个事件的底部,例如BL和BR。事件的位置越靠下,这些数字就越高,因为它们记录了与时间轴顶部的偏移量。
假设我们要定位事件E。我们选择将其定位在底部最小的一侧。因此,由min(BL,BR)决定。这是在演示中的功能min中实现的。然后,我们将E尽可能靠近时间轴的顶部放置,同时仍将其置于有效位置。有效位置是这样的位置,即没有其他事件重叠,并且事件的中心(该事件与时间轴的连接点)必须位于时间轴上的前一个点之后。设E'为与E相对的最后一个事件。设P为与E相同侧的最后一个事件。
测试以下三个位置就足够了。
1.将E的顶部与E'的底部对齐。这始终是有效位置,但对于R2而言不是很好。
2.将E的中心尽可能地对准E'的中心。这对于R2更好,但是当E的顶部现在与P重叠(E的顶部小于P的底部)时,这不是有效位置。
3.将E的顶部尽可能地对准P的底部。这对R2最好,但是当E的中心现在位于E'的中心之前时,这不是有效位置。
该算法仅按给定的顺序测试这些位置,并在当前测试的位置有效时覆盖E的位置。这样,将选择最佳的有效位置。
样式,详细信息和备注。 我添加了一些CSS标记来说明时间轴可以做什么。此标记和JavaScript代码应完全跨浏览器兼容。我确实没有使用ES6功能来实现最大程度的兼容性,但 Array.from
除外,该文件仍然具有良好的支持,并且在需要时可以在链接页面上为Internet Explorer提供polyfill。我自己对代码进行了最新版本的Firefox和Chrome测试。
该代码并未针对性能进行优化,但是由于该算法以线性时间运行,因此即使时间轴中有许多事件,运行该算法也不会出现问题。该演示会重新计算每个resize event上的布局,您可能希望在实时应用程序中对其进行限制。
在下面的演示中,您将看到有一个参数minSpace
。这是一个以像素为单位的空间,它留在时间轴上的两个连续点之间以及时间轴同一侧的两个事件之间。演示对此参数使用默认值10。
演示。 我创建了一个JSFiddle。如果愿意,还可以在此处将其作为摘要运行。我建议您调整预览窗口的大小,以便可以看到时间线布局的更新方式。
// wrap in anonymous function to not pollute global namespace
(function() {
// find the minimium element in an array, and the index of it
function min(arr) {
var ind = -1, min = false, i;
for (i = 0; i < arr.length; ++i) {
if (min === false || arr[i] < min) {
ind = i;
min = arr[i];
}
}
return {
index: ind,
value: min
};
}
// position events within a single timeline container
function updateTimeline(timeline, minSpace = 10) {
var events = Array.from(timeline.querySelectorAll('.event')),
tops = [0, 0],
bottoms = [0, 0],
minTops = [0, 0];
// determine height of container, upper bound
timeline.style.height = events.reduce(function(sum, event) {
return sum + event.offsetHeight;
}, 0) + 'px';
// position events in timeline
events.forEach(function(event) {
// find highest point to put event at
// first put it with its top aligned to the lowest bottom - this will
// always yield a good solution, we check better ones later
var h = event.offsetHeight,
y = min(bottoms),
x = (y.index === 0 ? 0 : 50),
b = y.value + h,
m = (tops[1 - y.index] + bottoms[1 - y.index]) / 2;
event.className = 'event';
event.classList.add('event--' + (y.index === 0 ? 'left' : 'right'));
// try to squeeze element up as high as possible
// first try to put midpoint of new event just below the midpoint of
// the last placed event on the other side
if (m + minSpace - h / 2 > minTops[y.index]) {
y.value = m + minSpace - h / 2;
b = y.value + h;
}
// it would be even better if the top of the new event could move
// all the way up - this can be done if its midpoint is below the
// midpoint of the last event on the other side
if (minTops[y.index] + h / 2 > m + minSpace) {
y.value = minTops[y.index];
b = y.value + h;
}
// update tops and bottoms for current event
tops[y.index] = Math.ceil(y.value);
bottoms[y.index] = Math.ceil(b + minSpace);
minTops[y.index] = bottoms[y.index];
// update tops and bottoms for other side, as applicable
if (y.value + (h / 2) + minSpace > bottoms[1 - y.index]) {
tops[1 - y.index] = bottoms[1 - y.index];
minTops[1 - y.index] = bottoms[1 - y.index];
}
bottoms[1 - y.index] = Math.ceil(Math.max(
bottoms[1 - y.index],
y.value + (h / 2) + minSpace
));
// put event at correct position
event.style.top = y.value + 'px';
event.style.left = x + '%';
});
// set actual height of container
timeline.style.height = (Math.max.apply(null, bottoms) - minSpace) + 'px';
}
// position events within all timeline containers on the page
function updateAllTimelines(minSpace = 10) {
Array.from(document.querySelectorAll('.timeline'))
.forEach(function(timeline) {
updateTimeline(timeline, minSpace);
});
}
// initialize timeline by calling above functions
var space = 10;
updateAllTimelines(space);
window.addEventListener('resize', function() {
updateAllTimelines(space);
});
}());
/* line in center */
.timeline {
position: relative;
width: 100%;
}
.timeline:before {
content: " ";
display: block;
position: absolute;
top: 0;
left: calc(50% - 2px);
width: 4px;
height: 100%;
background: red;
}
/* events */
.event {
position: absolute;
top: 0;
left: 0;
box-sizing: border-box;
width: 50%;
height: auto;
padding: 0 20px 0 0;
}
.event--right {
/* Move padding to other side.
* It is important that the padding does not change, because
* changing the height of an element (which padding can do)
* while layouting is not handled by the JavaScript. */
padding: 0 0 0 20px;
}
/* discs on timeline */
.event:after {
content: "";
display: block;
position: absolute;
top: calc(50% - 5px);
width: 0;
height: 0;
border-style: solid;
}
.event--left:after {
right: 0;
border-width: 10px 0 10px 20px;
border-color: transparent transparent transparent #de2d26;
}
.event--right:after {
left: 0;
border-width: 10px 20px 10px 0;
border-color: transparent #de2d26 transparent transparent;
}
/* event styling */
.event__body {
padding: 20px;
background: #de2d26;
color: rgba(255, 255, 255, 0.9);
}
<div class="timeline">
<div class="event">
<div class="event__body">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus varius sodales purus, id gravida ipsum accumsan quis. Donec ultrices orci quis ex consequat mollis. Etiam in gravida enim. Etiam efficitur lorem id turpis auctor gravida. Ut condimentum dolor nibh, in hendrerit leo egestas at.
</div>
</div>
<div class="event">
<div class="event__body">
Nam magna felis, malesuada vitae elementum sit amet, tempus sed eros. Etiam ullamcorper elementum viverra. Morbi dictum metus id nibh congue, at lacinia felis iaculis. Etiam pretium augue in erat lobortis viverra. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Suspendisse facilisis, velit vel placerat faucibus, massa est eleifend turpis, ac tempor dui turpis at mi. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.
</div>
</div>
<div class="event">
<div class="event__body">
Mauris malesuada arcu sed lacus tristique, a eleifend sem egestas. Pellentesque at malesuada nisi.
</div>
</div>
<div class="event">
<div class="event__body">
Nam et purus at elit vulputate molestie ac non eros. Proin mattis ligula velit, ut semper eros venenatis a. Vestibulum sagittis consectetur diam, molestie dapibus sem viverra a. Fusce felis augue, mollis id massa molestie, sagittis rutrum risus. In vel molestie elit, eget fringilla ante. Sed et elit blandit, tincidunt leo non, vehicula mi. Aenean tempus tincidunt eros vel tincidunt. Integer orci orci, gravida sit amet elit nec, luctus condimentum est.
</div>
</div>
<div class="event">
<div class="event__body">
Pellentesque sodales ultrices sem, eget convallis ante condimentum id. Fusce ac turpis ac ex tincidunt malesuada a ac est.
</div>
</div>
</div>
关于javascript - 创建像SO开发人员故事这样的垂直时间轴,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42919642/
我要在这里做的是遍历Storybook故事,以便可以对它们进行视觉回归测试: const puppeteer = require('puppeteer'); const { toMatchImageS
有人可以帮我解释一下涉及老虎机的 Rasa 故事吗: ## story with email * intent_request_email - utter_request_email * in
我们能够实现与 Instagram Stories 的共享,但无法实现与 Facebook Stories 的共享,如下 these指示 。尽管已安装并更新 Facebook 应用,Android 仍
我在使用 Facebook 开放图表故事时遇到问题。我只想发布一个带有对象标题的故事。我尝试使用开放图形对象调试器,我可以清楚地看到 og:title 已定义,但我发布的提要中没有标题。 我也尝试使用
如何将数据从 .properties 文件动态加载到 jBehave 故事文件?我一直在我的故事文件中使用 $ ,例如: When the stock is traded at price : $ T
我是 jbehave 的新手 我正在尝试通过 junit 执行 jbehave。 jbehave 似乎只从类路径加载故事文件。是否可以将其配置为从用户定义的路径中获取故事文件。 public clas
我们刚刚开始考虑使用 JBehave 进行验收测试,我想知道使用它的人是如何组织故事的编写和故事文件的存储的。目前只是在开发它们,所以我们将故事文件与实现它们的 Java 代码一起存储在资源文件夹中。
我正在尝试按顺序运行 jbehave 故事。 我的集成测试包结构如下所示 src/it/some/package/name/packageA/a.story src/it/some/package/n
我有一个 jBehave 故事如下; Scenario: Setup test GivenStories: common/story_1.story, common/sto
有人可以帮我运行一个 JBehave 故事吗?我在 Eclipse 中有一个 Maven 项目。 故事是: Meta: @author Nikolay Vasilev @bdd-talk: BG JU
我们有一个 Web 开发项目团队,我们决定使用单个存储库及其优缺点。我们将待办事项分成 Jira 故事,每个故事都有几个 FE 和 BE 任务。喜欢: ABC-1 显示猫 1.1. ABC-2 [FE
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引起辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the he
在我们公司,我们目前正在尝试建立故事 map (Jeff Patton)的概念。 我有以下问题:- 在具有交叉问题/任务的故事 map 中会发生什么?我们有贯穿整个项目的事件。故事 map 中的这些事
我想获得与远程 GIT 和 SVN 存储库同步的本地 GIT 存储库。 我正在执行的步骤如下: > git push Everything up-to-date > git pull Already
目前我所有的 .stories 文件都保存在 stories 目录中。随着我添加更多组件,它会增长。 相反,我想根据 Storybook 站点上的文档在组件级别添加每个组件的 .stories 文件:
我在网上读到 snapchat 和 instagram 有不同的方法来捕获视频,而不是在 Android 中使用相机 API,这允许它们向捕获的内容添加过滤器/贴纸等。 任何人都可以建议解决这个问题的
在 let returnTrip = Page(story: .ReturnTrip) 中它给了我们错误。我真的不知道为什么1 enum Story { case ReturnTrip (String
我们刚刚开始将Jira(带有Jira Agile插件-Scrum模板)用于我们的问题跟踪程序和敏捷计划。 我对故事和改进之间的差异(或预期的差异)感到困惑。我们所有的“东西”都写成故事。这些故事描述了
我正在为一个网站设计一个数据库,该数据库将至少表示 4 种不同的对象类型(文章、博客文章、照片、故事),每一种都有足够不同的数据要求来保证他们自己的表。我们希望用户能够发表任何这些类型的评论。评论的数
就目前情况而言,这个问题不太适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、民意调查或扩展讨论。如果您觉得这个问题可以改进并可能重新开放,visit
我是一名优秀的程序员,十分优秀!