gpt4 book ai didi

polymer - 使用 polymer 水平滚动

转载 作者:行者123 更新时间:2023-12-04 20:33:40 30 4
gpt4 key购买 nike

enter image description here
图片中显示 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>


demo

关于polymer - 使用 polymer 水平滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40297464/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com