未加星标

A Whistle-Stop Tour of the UIkit Framework

字体大小 | |
[前端(javascript) 所属分类 前端(javascript) | 发布者 店小二03 | 时间 2016 | 作者 红领巾 ] 0人收藏点击收藏

Whilst Bootstrap and Foundation might bethe two most popular front-end frameworks amongst web designers, in this article I’m going to introduce you tothefeatures of UIkit , a lightweight andmodular front-end framework which I use in almost all of my projects.

Note: This article assumes you’re familiar with how front-end frameworks work.Also, the main goal of this article isn’tto cover extensively individual parts of this framework (e.g. the grid system). Instead we’ll focuson brieflypresenting different usefulUIkit features.

Getting Started

UIkit is built and maintained by YOOtheme , a German company which specializes in building themes and applications for the web.

How to Download UIkit

There are afew differentoptions available for including UIkit in your projects. You can use a package manager likeBower, a Content Delivery Networklike cdnjs ,or you can download it manually from its GitHub page. Note thatUIkit requires jQuery , somake sure you’ve included that in your projects.

For the purposes of this tutorial, we’ll use cdnjs to pull the required UIkit files into our CodePen demos. Most of the time, for simplicity,we’ll have to include the uikit.min.css and uikit.min.js files. In the final two examples though, we’ll also add some additional files which aren’t included inthe core framework. Keep in mind that UIkit is modular, allowing us to load onlythe files that are actually needed.

You can learn aboutthe structure of UIkit on this page .

Customizing UIkit

The frameworkis fully customizable . Before downloadingwe’re able to overwrite its default styles and apply our very own. For instance, if we want to change the default breakpoints , we can visit the customizer page andcheck the Advanced Mode option. From there, wefind the Breakpoints section and add our new breakpoints. Then, we get the newly generated CSS file.


A Whistle-Stop Tour of the UIkit Framework
Browser Support

UIkit works in all recent browsers, specifically:


A Whistle-Stop Tour of the UIkit Framework
Image taken from UIkit’s GitHub page Useful UIkit Features

It’s time now to explore some useful UIkit features which you might want to use in one of your upcoming projects!

Flexbox and Grids

UIkit provides its Grid and Flex components for buildingresponsive layouts. To better understand how these components work, let’s create a simple layout. Before doing that, we have to add the uikit.min.css file to our example.

Here are the requirements:

On viewports up to767px wide, all columns are stacked vertically. On viewports wider than 767px, the widths of the first and third columns are 25% of the parent width, while the width of the second column is 50%of the parent width.

The markup looks like this:

<div class="uk-container uk-container-center">
<div class="uk-grid">
<div class="uk-width-medium-1-4">
<div class="card">
<!-- content here -->
</div>
</div>
<div class="uk-width-medium-1-2">
<div class="card">
<!-- content here -->
</div>
</div>
<div class="uk-width-medium-1-4">
<div class="card">
<!-- content here -->
</div>
</div>
</div><!-- /uk-grid -->
</div><!-- /uk-container -->

Notice the .card elements within our columns. For stylistic reasons, we’ll applysome basic styles:

.card {
background: #e0e0e0;
padding: 10px;
margin-top: 35px;
}

Here’s the Codepen demo:

As you can see from the demo above,the .card elements don’t fill the parent’s fullheight. Let’s assume we want to make that happen.

A quick solution might be to givetarget elements height: 100% , right?However, this doesn’t work in some browsers (e.g. Safari), so we have to abandon that approach andsearch foran alternative. One trick isto define the columns as flex containers by giving them the class of uk-flex . So now if we test the page again, we’ll see that the .card elements inherit the parent height. If you want to getsome more information about why thatsolution works, I recommend you look at thisStack Overflow thread .

Here’s the updated demo:

Creating Scroll-based Animations

If you’re a fan of scroll-based animations you’ll certainly appreciate UIkit’s Scrollspy component. This component allowsus to trigger animations and events as we scroll up and down the page. Let’s see a live example to understand how it works.

For this example, we’ll include the uikit.min.css and uikit.min.js files in our project.

The code structureis similar to the previous example. Our goal hereisto trigger different animations when the elements with the class of blue (in total five elements)enter the viewport. To implement this behavior, we add the data-uk-scrollspy attribute to the target elements; theirvalue beinga configurable object which controls the actual animation. For instance, the cls object propertystores the animation type :

&lt;div data-uk-scrollspy=&quot;{cls:'uk-animation-slide-left', repeat: true, delay: 300}&quot;&gt;

Part of the required markup is shown below:

<div class="uk-container uk-container-center">
<div class="uk-grid">
<!-- content here -->
<div class="uk-width-medium-1-2 uk-flex">
<div class="card blue" data-uk-scrollspy="{cls:'uk-animation-slide-left', repeat: true, delay: 300}">
<!-- content here -->
</div>
</div>
<div class="uk-width-medium-1-2 uk-flex">
<div class="card blue" data-uk-scrollspy="{cls:'uk-animation-slide-right', repeat: true,

本文前端(javascript)相关术语:javascript是什么意思 javascript下载 javascript权威指南 javascript基础教程 javascript 正则表达式 javascript设计模式 javascript高级程序设计 精通javascript javascript教程

主题: GitHubGitBootstrapCSSjQuery
分页:12
转载请注明
本文标题:A Whistle-Stop Tour of the UIkit Framework
本站链接:http://www.codesec.net/view/482068.html
分享请点击:


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 前端(javascript) | 评论(0) | 阅读(34)