How to Create Resizeable Split Views with Split.js and Split Grid

Mar 13, 2023 | Programming

If you ever wanted to create dynamic, resizeable split views on your web applications, you are in for a treat! In this guide, we’ll walk you through using Split.js and Split Grid, two unopinionated utilities that let you achieve this with minimal fuss.

Getting Started with Split.js

Split.js is a library that has evolved since 2014, creating split views seamlessly in float and flex layouts. Before we dive in, here is what you should know:

  • Zero Dependencies: No need to add extra libraries.
  • Tiny Size: Each utility is only between 1-2 KB gzipped, so it won’t bloat your application.
  • Speedy Performance: There’s no unnecessary overhead as it relies on pure CSS for resizing.
  • Unopinionated Behavior: It focuses solely on computing view sizes; the rest is up to you.

Using Split.js

To begin using Split.js, you first need to install it and then set up your HTML structure. Here’s how you can install it:

npm install split.js

Next, set up your HTML:


Panel 1
Panel 2

Now you can initialize Split.js with the following JavaScript:


const split = Split(['#split-container .split-pane'], {
  gutterSize: 10,
  minSize: 100
});

Understanding Split.js with an Analogy

Think of Split.js like a clever waiter in a coffee shop. You have two tables (the split panes), and the waiter (Split.js) knows just how much space to give each table without spilling any of your coffee (content). If one table (pane) has a larger group of friends today, the waiter allows it to grow while making sure the other table doesn’t feel cramped or rudely ignored.

Upgrading to Split Grid

If your layout is more grid-oriented, Split Grid is your friend. Similar to Split.js, but tailored for grid layouts, it supports modern browsers and offers the same performance and size benefits. Install and implement it like this:

npm install split-grid

Then, use the appropriate HTML structure and JS initialization similar to how you set up Split.js.

Troubleshooting

If you encounter issues such as the panes not resizing correctly or overlapping, consider the following:

  • Ensure that your CSS is correctly applied. The split panes should have appropriate dimensions and display properties.
  • Check if JavaScript is being executed without errors. Use your browser console to troubleshoot any issues that arise during initialization.
  • Try adjusting the gutterSize and minSize parameters during initialization for better results.

For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

Conclusion

By following this guide, you can now harness the power of Split.js and Split Grid to create beautiful, responsive, and functional split views in your web projects. At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox