Questa pagina è stata tradotta automaticamente dalla documentazione ufficiale, che si trova in https://vaadin.com/docs. Potrebbe contenere errori, inesattezze, o affermazioni errate. Vaadin non garantisce né rilascia alcuna dichiarazione in merito all’accuratezza, affidabilità, o tempestività della traduzione.
package com.vaadin.demo.component.scroller;
import com.vaadin.flow.component.Unit;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.card.Card;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.component.markdown.Markdown;
import com.vaadin.flow.component.orderedlayout.Scroller;
import com.vaadin.flow.router.Route;
@Route("scroller-basic")
public class ScrollerBasic extends Div {
private static final String EVENT_DETAILS = """
**Date & Time**
Saturday, July 19, 2025
9:00 AM – 5:00 PM (PDT)
**About This Event**
Join us for a full day of inspiring talks, hands-on workshops, and networking opportunities with industry leaders. Whether you're a seasoned developer or just starting out, there's something for everyone.
**Schedule**
- **9:00 AM** – Registration & Breakfast
- **10:00 AM** – Opening Keynote
- **11:30 AM** – Breakout Sessions
- **1:00 PM** – Lunch & Networking
- **2:30 PM** – Afternoon Workshops
- **4:30 PM** – Closing Remarks & Raffle
**What to Bring**
- Photo ID for check-in
- Laptop (optional, for workshops)
- Business cards for networking
**Parking**
Free parking available in Lot B. Street parking is limited.
**Contact**
Questions? Email us at events@techconf.io
""";
public ScrollerBasic() {
Card card = new Card();
card.setMaxWidth(400, Unit.PIXELS);
card.setTitle("Summer Tech Conference 2025");
// tag::snippet[]
Markdown markdown = new Markdown(EVENT_DETAILS);
Scroller scroller = new Scroller(markdown);
scroller.addThemeName("overflow-indicators");
scroller.setMaxHeight(300, Unit.PIXELS);
// end::snippet[]
card.add(scroller);
Button addToCalendar = new Button("Add to calendar");
card.addToFooter(addToCalendar);
add(card);
}
}
scroller-basic.tsx
import React from 'react';
import { Button } from '@vaadin/react-components/Button.js';
import { Card } from '@vaadin/react-components/Card.js';
import { Markdown } from '@vaadin/react-components/Markdown.js';
import { Scroller } from '@vaadin/react-components/Scroller.js';
const eventDetails = `
**Date & Time**
Saturday, July 19, 2025
9:00 AM – 5:00 PM (PDT)
**About This Event**
Join us for a full day of inspiring talks, hands-on workshops, and networking opportunities with industry leaders. Whether you're a seasoned developer or just starting out, there's something for everyone.
**Schedule**
- **9:00 AM** – Registration & Breakfast
- **10:00 AM** – Opening Keynote
- **11:30 AM** – Breakout Sessions
- **1:00 PM** – Lunch & Networking
- **2:30 PM** – Afternoon Workshops
- **4:30 PM** – Closing Remarks & Raffle
**What to Bring**
- Photo ID for check-in
- Laptop (optional, for workshops)
- Business cards for networking
**Parking**
Free parking available in Lot B. Street parking is limited.
**Contact**
Questions? Email us at events@techconf.io
`;
function Example() {
return (
<Card style={{ maxWidth: '400px' }}>
<div slot="title">Summer Tech Conference 2025</div>
{/* tag::snippet[] */}
<Scroller theme="overflow-indicators" style={{ maxHeight: '300px' }}>
<Markdown>{eventDetails}</Markdown>
</Scroller>
{/* end::snippet[] */}
<Button slot="footer">Add to calendar</Button>
</Card>
);
}
scroller-basic.ts
import '@vaadin/button';
import '@vaadin/card';
import '@vaadin/scroller';
import '@vaadin/markdown';
import { html, LitElement } from 'lit';
import { customElement } from 'lit/decorators.js';
import { applyTheme } from 'Frontend/demo/theme';
@customElement('scroller-basic')
export class Example extends LitElement {
private eventDetails = `
**Date & Time**
Saturday, July 19, 2025
9:00 AM – 5:00 PM (PDT)
**About This Event**
Join us for a full day of inspiring talks, hands-on workshops, and networking opportunities with industry leaders. Whether you're a seasoned developer or just starting out, there's something for everyone.
**Schedule**
- **9:00 AM** – Registration & Breakfast
- **10:00 AM** – Opening Keynote
- **11:30 AM** – Breakout Sessions
- **1:00 PM** – Lunch & Networking
- **2:30 PM** – Afternoon Workshops
- **4:30 PM** – Closing Remarks & Raffle
**What to Bring**
- Photo ID for check-in
- Laptop (optional, for workshops)
- Business cards for networking
**Parking**
Free parking available in Lot B. Street parking is limited.
**Contact**
Questions? Email us at events@techconf.io
`;
protected override createRenderRoot() {
const root = super.createRenderRoot();
applyTheme(root);
return root;
}
protected override render() {
return html`
<vaadin-card style="max-width: 400px">
<div slot="title">Summer Tech Conference 2025</div>
<!-- tag::snippet[] -->
<vaadin-scroller theme="overflow-indicators" style="max-height: 300px">
<vaadin-markdown .content="${this.eventDetails}"></vaadin-markdown>
</vaadin-scroller>
<!-- end::snippet[] -->
<vaadin-button slot="footer">Add to calendar</vaadin-button>
</vaadin-card>
`;
}
}
Direzione di scorrimento
Scroller supporta quattro direzioni di scorrimento: verticale, orizzontale, entrambe e nessuna. L’impostazione predefinita è entrambe.
Verticale
Quando lo scorrimento verticale è abilitato, gli utenti possono scorrere verso il basso se il contenuto supera l’altezza del contenitore. L’overflow orizzontale, tuttavia, viene ritagliato ed è inaccessibile—pertanto la larghezza del contenuto dovrebbe essere impostata al 100%.
Orizzontale
Quando lo scorrimento orizzontale è abilitato, gli utenti possono scorrere lateralmente se il contenuto supera la larghezza del contenitore. Tuttavia, l’overflow verticale viene ritagliato ed è inaccessibile—pertanto l’altezza del contenuto dovrebbe essere impostata al 100%.
Note
Utilizzi lo scorrimento orizzontale con cautela, poiché è meno comune e può essere più difficile per gli utenti notarlo e interagirvi—soprattutto su dispositivi non mobili.
Desktop
A parte i Grid, lo scorrimento orizzontale è poco comune nelle applicazioni desktop o business, poiché può risultare poco intuitivo e macchinoso.
Per migliorare l’usabilità, consideri l’uso di pulsanti per rendere lo scorrimento orizzontale più evidente e accessibile. Per elenchi scorrevoli orizzontalmente, è buona pratica indicare il numero totale di elementi ed evidenziare quali sono attualmente in vista.
Mobile
Lo scorrimento orizzontale o lo swipe è più comune su mobile, spesso utilizzato per la navigazione. Può anche aiutare a risparmiare spazio verticale—ad esempio, quando si visualizza contenuto meno importante come scorciatoie o immagini.
Quando la direzione di scorrimento è impostata su Both (l’impostazione predefinita), gli utenti possono scorrere sia verticalmente sia orizzontalmente se il contenuto va in overflow in una delle due direzioni.
Questa opzione è ideale per consentire agli utenti di spostarsi su elementi di grandi dimensioni, come immagini. Può anche fungere da fallback per layout responsive che potrebbero andare in overflow in determinate situazioni.
package com.vaadin.demo.component.scroller;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.component.html.Image;
import com.vaadin.flow.component.orderedlayout.Scroller;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.server.streams.DownloadHandler;
@Route("scroller-both")
public class ScrollerBoth extends Div {
public ScrollerBoth() {
// tag::snippet[]
Scroller scroller = new Scroller();
scroller.setWidthFull();
scroller.setHeight("300px");
DownloadHandler imageHandler = DownloadHandler.forClassResource(
getClass(), "/images/reindeer.jpg", "reindeer.jpg");
Image img = new Image(imageHandler,
"A reindeer walking on a snowy lake shore at dusk");
scroller.setContent(img);
add(scroller);
// end::snippet[]
}
}
scroller-both.tsx
import React from 'react';
import { Scroller } from '@vaadin/react-components/Scroller.js';
import img from '../../../../../src/main/resources/images/reindeer.jpg?url';
function Example() {
return (
// tag::snippet[]
<Scroller style={{ height: '300px', width: '100%' }}>
<img src={img} alt="A reindeer walking on a snowy lake shore at dusk" />
</Scroller>
// end::snippet[]
);
}
scroller-both.ts
import '@vaadin/scroller';
import { html, LitElement } from 'lit';
import { customElement } from 'lit/decorators.js';
import { applyTheme } from 'Frontend/demo/theme';
import img from '../../../../src/main/resources/images/reindeer.jpg?url';
@customElement('scroller-both')
export class Example extends LitElement {
protected override createRenderRoot() {
const root = super.createRenderRoot();
applyTheme(root);
return root;
}
protected override render() {
return html`
<!-- tag::snippet[] -->
<vaadin-scroller style="height: 300px; width: 100%">
<img src="${img}" alt="A reindeer walking on a snowy lake shore at dusk" />
</vaadin-scroller>
<!-- end::snippet[] -->
`;
}
}
Nessuna
Utilizzi None per nascondere il contenuto in overflow in entrambe le direzioni. Non vengono fornite barre di scorrimento e il contenuto ritagliato è inaccessibile. None è utile in scenari a dimensione fissa o con layout fisso in cui l’overflow causerebbe problemi.