Code Monkey home page Code Monkey logo

paytonshaltis / freighter Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 807 KB

๐Ÿš‚ Freighter is a highly-customizable HTML carousel library featuring a number of dynamic properties affecting carousel items and transitions. Most prominently, it gives complete control over the resizing method (for responsive layouts) as well as the wrapping method (for content display).

Home Page: https://paytonshaltis.github.io/freighter

License: MIT License

TypeScript 99.12% JavaScript 0.88%
carousel carousel-slider css javascript typescript responsive html library slider freighter freighterjs

freighter's Introduction

Freighter Logo

Version Activity

Freighter - The Responsive Carousel Library

Create responsive, dynamic, and customizable carousels. Control the wrapping and resizing behavior with a variety of built-in methods for ensuring your carousel looks great and works well on any device. Style and customize your carousel with properties including autoscroll behavior, specialized transitions, number of items to show and scroll by, and many more.

Documentation

Full documentation for Freighter can be found on the official documentation website for Freighter. Here, you will find detailed download instructions, detailed descriptions of all carousel properties, and useful demos for inspiration.

Downloading

Visit the downloads page of the Freigher website to find every version of Freighter in all downloadable formats, including the original TypeScript source, JavaScript UMD and ES6 bundles, and the NPM release.

Usage

All Carousel Examples

See the official documentation for more detailed examples, code snippets, and live examples.

Usage Basics

In order to create a Freighter carousel, you will need a <div> with some unique id, which will be targeted and act as the outermost container for your carousel. This element should contain as many other <div>s as you'd like, each of which will become a carousel item.

Use the Freighter() constructor to convert the element into a carousel. Note that this code should execute after the element has been loaded to the DOM, otherwise, it will not be found. The constructor requires your container's id, a valid resizing method, a valid wrapping method, and a CarouselProperties object containing any other customizable carousel properties that you wish to initialize your carousel with. All of the properties within this object can be changed later with methods such as setCarouselProperties(), making Freighter carousels dynamic.

Below is an example of calling the constructor in a JavaScript file whose environment is using ES6 modules. Notice that the Freighter class is imported; for environments that import modules differently (require(), etc.), see the downloads page for the UMD module.

import Freighter from "freighter-1.0.2.js";

const myCarousel = new Freighter(
  "container-id",
  "stretch-scale",
  "wrap-smart",
  {
    numItemsVisible: 3,
    scrollBy: 1,
    itemHeight: 3,
    itemWidth: 5,
    transitionDuration: 250,
  }
);

Next Steps

Eager to learn more about creating responsive carousels? Check out these links for recommended next steps!

  • Learn about the powerful resizing and wrapping methods.
  • Get an overview of all dynamic carousel properties that can be used to customize your carousel.
  • Check out some carousel demos to see what's possible with Freighter and spark some inspiration for your next project.

freighter's People

Contributors

paytonshaltis avatar

Stargazers

 avatar

Watchers

 avatar

freighter's Issues

Add a vertical option.

Allow the constructor to be called with an optional parameter that turns the carousel into a vertical container.

Create an interface for instantiating carousels.

Need to have an easy way for a user to add carousels to their document without them worrying about pasting several wrappers with unique IDs and class names.

Ideally, the user would just include a single div in their markup which will be replaced by JS with the appropriate elements that are marked with unique IDs for appropriate styling.

Ability to add additional event handlers to the arrows.

In addition to just progressing the carousel, the two control buttons should be able to be interacted with, giving the programmer an interface to add more event listeners. Should be careful not to remove them when creating new carousel instances, and shouldn't forget to add them to the state or options so that they are carried over into the next instantiation.

Button hiding not working.

  • Z-index change does not affect the chevron icon within the button.
  • If there is no background color to the carousel, the button will still be visible.

May be better to completely remove these buttons from the DOM and just have the click event handler be called by the auto-scroll interval.

Take proper action against removed elements.

Though likely uncommon, there is still the possibility that an HTMLElement of the carousel (anywhere from the largest container to one of the wrappers or even an individual item) could be modified or removed. Proper action should be taken to ensure that this does not occur.

  • Add exception handling for parts of the code that access a specific child element (.children[1].children[0] type of code).

Review code and possibly refactor / streamline.

The code in Carousel.ts is starting to get quite long and even a little messy. Should really go ahead and look through the entire file and organize what can be organized, potentially moving some lesser-used and larger methods out into some utility folder. Variable names, method calls, and comments need to be more consistent in order to increase the longevity of the project.

For example, many of the styling and configuration methods can likely be moved into their own designated files. This removes the one-time methods from clogging up most of the class's implementation file.

Determine which attributes of a carousel should be changeable.

For example, the complexity involved with changing between wrapping methods means that it is likely not practical to implement this as an option that can be changed on-the-fly. Other methods including the ability to change resizing modes are questionable: for the most part, the resizing strategy for a carousel is likely to remain the same.

By limiting the number of options that can be changed on the fly, the amount of bugs that can appear is decreased significantly. It also reduces the amount of redundant code and possible combinations of options that need to be checked when others change.

Either way, this should be formalized somewhere (some markdown file) and eventually integrated into the informational webpage.

Allow dynamic addition / subtraction of carousel items.

Should provide some way of adding or removing carousel items after the instantiation of the Carousel object. This cannot be done by just adding them to the originally named containing div, since its children will have been modified by the constructor.

May want to implement some instance methods within the Carousel class that accept an element to add or remove. When an element is added or removed, the carousel may need to be reinitialized. The position of the carousel should try to be preserved so that adding an element does not reset the position back to the start.

Allow the user to specify their own transitions.

Though a transition is required to fire the transitionend events, it can be set to 1ms if the user wants instant movement, or the transition time, delay, or functions could be customized to the user's exact specifications.

Add a timed scroll functionality.

Implement automatic scrolling through a Carousel with the following features:

  • Specify and change the amount of time to scroll from one page to the next.
  • Whether or not scrolling should stop if the user mouses over the Carousel.
  • Which direction the automatic scrolling should occur.

Scrollbar messes up layout of resizing carousels.

As mentioned in #18, containers with carousels need to either always or never show a scrollbar or risk having some of the content of their carousels cut off. One strategy to try and fix this issue could include comparing the starting width and the ending width of the container, and if they are different, continue to resize.

Remove unneeded styles from carousel items.

Some of the testing styles in the .carousel-item CSS class such as background color, color, line height, etc. need to be removed in order to prevent styles from being carried over into the child elements.

Allow different carousels to have unique properties.

Currently, all carousels share the same properties including size, number of visible items, and the number of items to scroll by. Each carousel should ideally be styled on its own without conflicting with other carousel items.

Begin designing the webpage layout.

Before documentation can begin being added to the webpage, a good design should be created for it. Notable features include:

  • Home page with simple demos
  • Getting started page
    • Downloading and installing
    • First carousels
  • Detailed demonstration page with most of the offered carousel effects
  • Detailed documentation page with all of the important interface options

Reset top and bottom carousel pointers when they advance too far.

First mentioned in #37.

Adding and removing defaults to the last index means that if we are viewing wrapped items, they are technically placed behind them. This is caused by the top and bottom pointers never changing if they go above the length of the carousel or below 0, and relying on modulo to perform the operations. The fix would just be to set the pointers correctly if they move too far in the other direction.

This issue is marked as a bug and an enhancement because while the issue does not break the code, it is undesirable.

Should also take a look at the code from #40 that sets the bottom pointer to 0 if the length of the carousel items is 0 to avoid infinite looping; this solution may no longer be required with the resolution of this issue.

Create a better interface for creating carousels.

Need to implement a few things to ease the user's Carousel management experience:

  • Rename the CarouselManager class to Carousel, and the Carousel class to something else (maybe CarouselInternal?).
  • Provide different setters for changing the properties of a Carousel, as well as setters that take in any combination of the parameters, the object itself, etc.
  • Add getters to what is now the CarouselManager class so that the user can get a full report of the current state of their Carousel.

Create a layout with Bootstrap columns.

Using Bootstrap as the framework, the webpage should start to be implemented using the design from #35. Specifically, the main container for each page as well as the general set of columns for each page should be responsive for each device, with content appearing, disappearing, and repositioning correctly based on the viewport width.

Fix position of different sized buttons.

If the left and right arrow buttons are larger than the containing div, this div should grow in order to fit the buttons. If the buttons are smaller than the height of the div, they should be centered, rather than pushed to the bottom like they are now.

With resizes implemented in #15, the stretch-scale resizing method means that the height of a carousel can change, so the button sizes will need to be checked with this type of carousel.

Give the programmer the option to end wrapping.

If a carousel has a number of items visible that is not a multiple of the total number of items, the wrapping causes elements to lose their grouping on the screen. For example, imagine a carousel shows 3 elements at a time and has 4 items:

[ 1 2 3 ] 4

Scrolling by 2 now would result in:

[ 3 4 1 ] 2

Rather than the idealized behavior after this issue is implemented:

[ 2 3 4 ] 1

This would make the eventual carousel timeline in #29 much more clear, as there are two pages that can be generated by scrolling by 2:

[ 1 2 3 ] 4
[ 2 3 4 ] 1

Optional timeline element for scrolling through carousel.

Add an optional 'timeline' that shows the user's current progress through a carousel. Will need to keep the following in mind:

  • Maybe let the user choose where to position this in relation to the Carousel.
  • How to style the timeline.
  • How the timeline should handle uneven scrolling positions (show 4, scroll 3, total 8). May just show the current page based on the original breakdown, and if there are more items on the screen from that fraction of the total items.

Create a Carousel class, refactor accordingly.

Currently, the implementation for multiple carousels involves arrays of almost every required property. Rather than deal with this confusion, a single Carousel class should be created, that way each carousel can maintain its own state within a single object.

This issue also makes room for the resolution of #2, which will essentially serve as the constructor of the class.

Stretch-populate resizing method.

One of the originally-planned resizing methods included the following:

  • stretch-populate: This is like stretch-gap, except when there is enough space to add a carousel item, the carouselItemsVisible attribute can increase or decrease to add or remove items in the carousel.

This task should be its own issue, as opposed to being lumped in with #15. This task also seems to naturally follow from #16, since making the carousel too large or small will end up calling one of these methods to add or remove carousel items.

Allow scrolling via touch or mouse events.

Should implement a way of scrolling through the carousel without using the buttons, and instead dragging the entire carousel to the right or left. Should still only move the currentScrollBy amount.

Flex gap property not supported on early versions of Safari iOS.

Because 'gap' is not a supported property on iOS Safari, it means that items are slightly off in their positioning when a carousel of type stretch-gap is constructed. The easy fix is to require the latest version of iOS, but alternatively, margins or some other workaround may be implemented.

Add alternate slide transformations.

Rather than just having slides translate along the X-axis, it may be a good idea to introduce a few alternatives, such as a fade-in, that can be offered to the programmer.

Create / find train SVGs for site landing page.

A really cool idea for the project webpage is to have a freight train carousel at the very top, with some of the language's features included in little shipping boxes. In order to make this look right, need to find or create some simple SVGs for the engine as well as some freight cars to show the features.

Implement wrapping functionality.

When the user scrolls through the carousel, the DOM must be manipulated in a way where items from the front of the carousel are moved to the back and vice-versa in order to allow for the wrapping functionality.

Will need to base some of this implementation on #4 in the case that the user has fewer carousel items in their carousel than the number of visible items at a time.

Add the wrap-none wrapping method.

As mentioned in #44 and #48:

  • wrap-none: Once the carousel hits either of the two ends, scrolling will not be allowed to continue. This will take wrap-smart as a base, since it stops scrolling past the ends early. Once this end is reached, the canScroll flag can be set to false to prevent further navigation.
    • The beauty in this method is that pointer values don't need to be modified beyond how they are in wrap-smart.

Allow an array of scrolling amounts.

Rather than restricting the user to a single scrollBy value, allow the user to pass an array in as this option. The program will then alternate between values in this array to determine the next scrollBy amount.

Implement jumping to a specific page of the carousel.

In order to prepare for the implementation of the timeline in #29 as well as the wrap-jump wrapping method in #53, some method for jumping to the desired page in the carousel should be created. Doing this before the issues mentioned above means that the process will be more streamlined.

Add methods for changing carousel variables.

In order for the carousel to be able to change size with the window, basic methods should be provided that allows a user to change most of the attributes of a carousel. This will require more than just reassigning object attributes: the carousel may need to be reinitialized if visibility amounts change.

Create the wrap-jump wrapping method.

First mentioned in #44 and #49, this makes more sense to keep in its own issue. Requires the completion of #52 beforehand, and will likely be done as a part of the 2.0.0 release milestone due to the amount required and the small amount that it really adds.

Allow automatic carousel resizing with parent container.

For responsiveness, a carousel should be able to resize appropriately according to its containing parent element. Below are a few of the resize methods that should be implemented, listed in their expected order of complexity:

  • none: The size of the carousel is fixed according to the size of the elements.
  • stretch: The carousel stretches horizontally. Only the height of each carousel item is changed in order to fill the entire width of the carousel.
  • stretch-gap: The carousel stretches horizontally. The size of each carousel item is preserved, but the gap increases/decreases. The gap provided to the constructor, in this case, serves as the minimum gap between carousel items.
  • stretch-scale: This is like stretch, except the original aspect ratio of the carousel items is preserved. This means that the height of the carousel changes.

Find a way to add / remove items without creating a new Carousel instance.

Currently, adding and deleting carousel items creates a 'flashing' effect due to a new carousel being constructed. This only seems to occur with the resize mode of stretch-scale, since the height has to flex-shrink and grow again. Perhaps there is a way to avoid flex shrinking and growing when adding new items only with this resizing method.

Need to be careful not to mess with any other features while making this change. Specifically, changing the resizing method of a carousel requires these resizing functions to be called.

Resize should be checked on carousel parent.

Rather than checking for the window to be resized to change the size of a carousel, the parent element of the carousel should be checked. This would cover cases where there are resizeable containers within the document that contain carousels.

Allow carousel items of differring widths.

This will likely be a large feature to implement, but I think it is an important one. A carousel should be able to progress just by the width of the next carousel item and allow for multiple different widths of carousel items. With this comes a whole slew of potential issues, including how to deal with preserving the number of carousel items that are visible when the width of each can vary.

Add home page with carousel train demo.

Now that the carousel demo with the train seems to be working well, it may be time to begin thinking about the home page of the site. The hero section should feature the demo carousel with both automatic and manual scrolling features, potential resize methods, and wrap-smart.

Rename classes and IDs to avoid possible name collision.

Currently, the ID and class names are pretty generic and likely to be used by the client. To avoid any kind of namespace collision, these should either be documented or made very specific and unlikely to be used by a programmer.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.