-
Notifications
You must be signed in to change notification settings - Fork 80
kb(carousel):thumbnail scrollable navigation #743
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1ab53dd
kb(carousel):thumbnail scrollable navigation
xristianstefanov 41581eb
code improvements
40b710d
Update knowledge-base/carousel-thumbnail-scrollable-navigation.md
dimodi 3b93e9b
Update knowledge-base/carousel-thumbnail-scrollable-navigation.md
dimodi 646e6f5
Update knowledge-base/carousel-thumbnail-scrollable-navigation.md
xristianstefanov e8b73a5
Update knowledge-base/carousel-thumbnail-scrollable-navigation.md
xristianstefanov 2a1e391
Update knowledge-base/carousel-thumbnail-scrollable-navigation.md
xristianstefanov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
150 changes: 150 additions & 0 deletions
150
knowledge-base/carousel-thumbnail-scrollable-navigation.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| --- | ||
| title: Carousel Thumbnail Scrollable Navigation | ||
| description: How to use thumbnails in scrollable navigation for the Carousel? | ||
| type: how-to | ||
| page_title: Carousel Thumbnail Scrollable Navigation | ||
| slug: carousel-kb-thumbnail-scrollable-navigation | ||
| position: | ||
| tags: telerik,blazor,carousel,thumbnail,navigation,images | ||
| ticketid: 1550292 | ||
| res_type: kb | ||
| --- | ||
|
|
||
| ## Environment | ||
| <table> | ||
| <tbody> | ||
| <tr> | ||
| <td>Product</td> | ||
| <td>Carousel for Blazor</td> | ||
| </tr> | ||
| </tbody> | ||
| </table> | ||
|
|
||
|
|
||
| ## Description | ||
| How to add a thumbnail scrollable navigation below the page/image in Carousel? This would be a nice addition, which would allow independent scrolling from that of the current page. It will also be clickable in the same way that the dots are to jump to the selected page. | ||
|
|
||
| ## Solution | ||
| To add a thumbnail scrollable navigation: | ||
|
|
||
| 1. Add HTML `<div>` container under the `Carousel` markup. | ||
| 2. Apply custom CSS with the needed styles to the container. | ||
| 3. Inside the `<div>`, loop through all the images in `Carousel` and define them in a smaller size. | ||
| 4. Optionally, use a javascript function that keeps the synchronization of the `AutomaticPageChange` and the thumbnail. | ||
|
|
||
|  | ||
|
|
||
| >caption Component | ||
|
|
||
| ````CSHTML | ||
| @inject IJSRuntime JSRuntime; | ||
|
|
||
| <TelerikCarousel Data="@CarouselData" | ||
| Width="600px" Height="384px" | ||
| PageChanged="PageChangedHandler" Page="PageIndex"> | ||
| <Template> | ||
| <div class="image-with-text"> | ||
| <p>Showing image @(context.ImageID) of @CarouselData.Count.ToString().</p> | ||
| <img src="@context.ImageUrl" alt="Photograph" width="612" height="384" /> | ||
| </div> | ||
| </Template> | ||
| </TelerikCarousel> | ||
|
|
||
| <div class="container-nav"> | ||
| <div class="images-nav"> | ||
| @foreach (var img in CarouselData) | ||
| { | ||
| <img @onclick="@(() => PageChangedHandler(img.ImageID))" id="@img.ImageID" | ||
| class="image-thumbnail" | ||
| src="@img.ImageUrl" alt="Photograph" /> | ||
| } | ||
| </div> | ||
| </div> | ||
|
|
||
| <!-- Move the JavaScript code to a separate .js file in the actual app --> | ||
| <script suppress-error="BL9992"> | ||
dimodi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| function ScrollToCurrentPage(imgId) { | ||
| var elem = document.getElementById(imgId); | ||
| if (elem) { | ||
| elem.scrollIntoView(); | ||
| } | ||
| } | ||
| </script> | ||
|
|
||
| @code { | ||
| public List<CarouselModel> CarouselData { get; set; } | ||
| public int PageIndex = 1; | ||
|
|
||
| public async Task PageChangedHandler(int newPage) | ||
| { | ||
| PageIndex = newPage; | ||
| await JSRuntime.InvokeVoidAsync("ScrollToCurrentPage", newPage); | ||
| } | ||
|
|
||
| protected override Task OnInitializedAsync() | ||
| { | ||
| CarouselData = Enumerable.Range(0, 13).Select(x => new CarouselModel | ||
| { | ||
| ImageID = x + 1, | ||
| ImageUrl = $"https://demos.telerik.com/blazor-ui/images/photos/{x % 7 + 1}.jpg" | ||
| }).ToList(); | ||
|
|
||
| return base.OnInitializedAsync(); | ||
| } | ||
|
|
||
| public class CarouselModel | ||
| { | ||
| public int ImageID { get; set; } | ||
| public string ImageUrl { get; set; } | ||
| } | ||
| } | ||
|
|
||
| <style> | ||
| html, body { | ||
| max-width: 100%; | ||
| overflow-x: hidden; | ||
| } | ||
|
|
||
| /* center the Carousel horizontally */ | ||
| /* k-scrollview is the default component class */ | ||
| .k-scrollview { | ||
| margin: 0 auto; | ||
| } | ||
|
|
||
| /* enable absolute positioning inside the Carousel template */ | ||
| .image-with-text { | ||
| position: relative; | ||
| } | ||
|
|
||
| /* style the overlay text inside the Carousel */ | ||
| .image-with-text > p { | ||
| position: absolute; | ||
| top: 1rem; | ||
| left: 1.6rem; | ||
| color: rgba(255, 255, 255, .8); | ||
| margin: 0; | ||
| font-style: italic; | ||
| text-shadow: 1px 1px 2px rgba(0, 0, 0, .8); | ||
| } | ||
|
|
||
| .images-nav { | ||
| text-align: center; | ||
| margin-top: 7px; | ||
| display: flex; | ||
| width: 550px; | ||
| overflow-x: auto; | ||
| } | ||
|
|
||
| .image-thumbnail { | ||
| width: 80px; | ||
| height: 50px; | ||
| border: outset; | ||
| margin: 1px 1px 1px 1px | ||
| } | ||
|
|
||
| .container-nav { | ||
| display: flex; | ||
| justify-content: center; | ||
| } | ||
| </style> | ||
| ```` | ||
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The to-do list contains too much low-level advice, but lacks the conceptual stuff.