- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
图片中显示 People also search for
的部分,有一个可滚动的水平项目列表。我必须使用 polymer 做同样的事情,但找不到任何类似的东西。我已经实现了垂直列表,但不确定水平列表。
另一个问题是,在这种情况下是否可以使用类似 viewpager 的组件? Paper-Tabs 确实提供了此功能,但是滑动手势不起作用。仅当我们单击选项卡时页面才会更改。
最佳答案
Google 搜索中的可滚动建议框是一个带有水平滚动溢出的简单框(不像标签 View 中那样分页)。该意见箱的滚动部分可以通过两个嵌套的 div
轻松实现。容器,带外 div
样式为 overflow-x: auto
和内部 div
样式为 white-space: nowrap
,如本例所示:
<div style="overflow-x: auto">
<div style="white-space: nowrap">
<template is="dom-repeat" items="[[suggestions]]">
...
</template>
</div>
</div>
overflow-x: auto
告诉浏览器在边缘溢出时呈现滚动条并剪辑溢出内容。
white-space: nowrap
发生行溢出时禁用元素换行,以便元素保留在同一行上。
window.addEventListener('WebComponentsReady', () => {
class XFoo extends Polymer.Element {
static get is() { return 'x-foo'; }
static get properties() {
return {
suggestions: {
value: () => [
{title: 'polymer gestures', url: 'https://www.google.com/search?q=polymer+gestures'},
{title: 'polymer elements', url: 'https://www.google.com/search?q=polymer+elements'}
]
}
};
}
}
customElements.define(XFoo.is, XFoo);
customElements.define('x-suggestions', class extends Polymer.Element {
static get is() { return 'x-suggestions' }
static get properties() {
return {
suggestions: Array
};
}
_onClickFeedback() {
console.log('feedback');
}
_onClickClose() {
this.dispatchEvent(new CustomEvent('close', {detail: {el: this}}));
}
});
});
html {
font-family: Roboto, Arial, Helvetica, sans-serif;
}
<head>
<base href="https://polygit.org/polymer+v2.3.1/components/">
<script src="webcomponentsjs/webcomponents-loader.js"></script>
<link rel="import" href="polymer/polymer.html">
<link rel="import" href="iron-icons/iron-icons.html">
<link rel="import" href="iron-icon/iron-icon.html">
</head>
<body>
<x-foo></x-foo>
<dom-module id="x-foo">
<template>
<style>
x-suggestions {
width: 350px;
}
</style>
<x-suggestions suggestions="[[suggestions]]"></x-suggestions>
</template>
</dom-module>
<dom-module id="x-suggestions">
<template>
<style>
:host {
display: block;
background: #f8f8f8;
color: #6a6a6a;
padding-bottom: 1rem;
}
.title {
margin: 0;
padding: 1rem 1rem 1rem 1.3rem;
}
.feedback {
text-decoration: none;
font-style: italic;
color: #6a6a6a;
margin: 1rem;
}
.suggestion {
text-decoration: none;
font-weight: bold;
color: black;
}
.suggestions-outer {
overflow-x: auto;
}
.suggestions-inner {
white-space: nowrap;
}
.suggestion-box {
display: inline-flex;
margin: 0.2rem;
padding: 1em 1em 1em 0.5em;
border: solid 1px #ddd;
border-radius: 2px;
}
.header {
display: flex;
border-top: solid 2px #e9e9e9;
}
.close-btn {
background: transparent;
border: none;
margin: 10px 10px 10px auto;
font-size: 1rem;
color: #6a6a6a;
cursor: pointer;
}
.icon-search {
color: #717171;
--iron-icon-height: 28px;
--iron-icon-width: 28px;
}
</style>
<header class="header">
<h3 class="title">People also search for</h3>
<button class="close-btn" title$="Close" on-click="_onClickClose">✕</button>
</header>
<div class="suggestions-outer">
<div class="suggestions-inner">
<template is="dom-repeat" items="[[suggestions]]">
<div class="suggestion-box">
<a class="suggestion" target$="_blank" href$="[[item.url]]">
<iron-icon class="icon-search" icon="search"></iron-icon>
<span>[[item.title]]</span>
</a>
</div>
</template>
<a href="#" class="feedback" on-click="_onClickFeedback">Feedback</a>
</div>
</div>
</template>
</dom-module>
</body>
关于polymer - 使用 polymer 水平滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40297464/
我有一个Polymer元素,并且在它的Javascript中,我试图找到它的宽度和高度,就像它在DOM中一样。我尝试了很多方法,但总是得到0。 最佳答案 ...这是对我有用的一个: 将Polymer.
如何在“polymer 3”元素中使用“polymer 2”元素?由于元素在shadow dom内部不起作用,因此以下内容不起作用。 static get template() { retur
在我的 React 项目中,我使用 ES6 模块已有一段时间了。在我的 React 组件中,我将使用 import: import {f1,f2} from "./myLib"; 在我的 polyme
我想知道是否有用于聚合物元素的CDN,因为您必须始终下载元素,并且通过CDN导入它会更方便。在Google上找不到任何内容?还有什么理由不存在它,或者仅仅是因为它太新了? 最佳答案 我现在不知道任何托
我试图在以下取自 Polymer Path 的上下文中理解主机和目标(和元素)和 Polymer Data Flow文档。 考虑下图: 现在考虑以下语句(来自同一个 documentation ):
polymer 文档具有以下两种方式绑定(bind)示例: Polymer({ is: 'custom-element', properties:
如果我想从具有聚合物的数组中创建纸张选择器,则看起来很麻烦: ... [[item
我最近安装了 nodejs,凉亭。然后,我使用以下命令安装了 polymer : npm install -g polymer 然后,我添加了 polymer 安装路径: C:\Users\\AppD
我正在尝试通过 querySelector 或等效方法获取在另一个元素中定义的自定义 Polymer 元素。我的代码如下: Polymer({ ready: function(){
我正在使用 Polymer v3 开发一个 Web 组件,并且需要在我的新组件的模板 HTML 中包含一些在旧式 Polymer 2 组件中定义的自定义元素。 由于 Polymer 3 不再支持 HT
我有两个 polymer 元件: 它们都是父元素内的子元素 ,并且每个都位于不同的文件中。 在 ,我有一个 ,里面有一些在那里通过点击事件来获取它的值。 目标是:在 另一方面,我想从具有如下 ur
任何人都可以向我指出使用 Polymer CLI 中的 Polymer 2 和 polymer-build 的教程吗?当我使用 polymer-starter-kit 中的任何示例并使用 polyme
我需要知道何时可以开始以编程方式使用我的自定义 Polymer 元素。元素还在undefined即使在我的 window.onload处理程序。是否有使用 Polymer 1.0 正确执行此操作的既定
我正在使用 Polymer Starter Kit 作为应用程序的基础。所以,这是一个路由到特定部分的单页应用程序。我的索引基本没变,你看这里https://github.com/PolymerEle
polymer 菜鸟... 我正在尝试根据 Polymer API 文档创建一个自定义元素,我的主页如下所示: Polymer
我在迁移到 Polymer 1.0 时遇到了一些问题 我的主要问题是“style-scope”和“my-element”类被应用于元素中的每个子节点。使用这样的东西时这不是问题:
图片中显示 People also search for 的部分,有一个可滚动的水平项目列表。我必须使用 polymer 做同样的事情,但找不到任何类似的东西。我已经实现了垂直列表,但不确定水平列表。
我想创建一个用户只能实例化一次的元素。 到目前为止,我能想到的最好的做法是在匿名函数中定义元素,并在发现该元素已存在时抛出错误。有没有办法让它拒绝被创建? (function(){ var sin
我有一个简单的元素,它只允许您一次选择一个本地文件,然后将所选文件显示为您可以删除的项目,如下所示: 该组件本身工作得很好,问题是我在同一页面中有另一个相同类型的组件,但在不同的父元素(和隐藏)内。如
我正在深入研究 Polymer 1.0 元素,我对计算的属性有点好奇。 例如,在 纸抽屉面板.html , … … … Polymer({ is: 'paper-
我是一名优秀的程序员,十分优秀!