locomotive-boilerplate

? Front-end boilerplate for projects by Locomotive.

  • 所有者: locomotivemtl/locomotive-boilerplate
  • 平台:
  • 許可證: MIT License
  • 分類:
  • 主題:
  • 喜歡:
    0
      比較:

Github星跟蹤圖

Installation

npm install mbp -g

Usage

# init your project
mbp init locomotivemtl/locomotive-boilerplate <directory>

# and start it
npm start

Configuration

Change the mentions of boilerplate for your project's name in mconfig.json. It is based on modularBP.

Learn more

Build

gulp is our build system. It compiles our styles and scripts, generate svg sprites, live reload the browser and minify everything.

Tasks

# watch
npm start

# compile
npm run compile

# minify
npm run build

Learn more

Styles

Sass is our CSS preprocessor. Autoprefixer is also included.

Architecture

ITCSS is our CSS architecture.

  • settings: Global variables, site-wide settings, config switches, etc.
  • tools: Site-wide mixins and functions.
  • generic: Low-specificity, far-reaching rulesets (e.g. resets).
  • elements: Unclassed HTML elements (e.g. a {}, blockquote {}, address {}).
  • objects: Objects, abstractions, and design patterns (e.g. .o-layout {}).
  • components: Discrete, complete chunks of UI (e.g. .c-carousel {}).
  • utilities: High-specificity, very explicit selectors. Overrides and helper
    classes (e.g. .u-hidden {})

source

Naming

We use a simplified BEM syntax.

.block .block_element -modifier

Namespaces

We namespace our classes for more transparency.

  • o-: Object that it may be used in any number of unrelated contexts to the one you can currently see it in. Making modifications to these types of class could potentially have knock-on effects in a lot of other unrelated places.
  • c-: Component is a concrete, implementation-specific piece of UI. All of the changes you make to its styles should be detectable in the context you’re currently looking at. Modifying these styles should be safe and have no side effects.
  • u-: Utility has a very specific role (often providing only one declaration) and should not be bound onto or changed. It can be reused and is not tied to any specific piece of UI.
  • s-: Scope creates a new styling context. Similar to a Theme, but not necessarily cosmetic, these should be used sparingly—they can be open to abuse and lead to poor CSS if not used wisely.
  • is-, has-: Is currently styled a certain way because of a state or condition. It tells us that the DOM currently has a temporary, optional, or short-lived style applied to it due to a certain state being invoked.

source

Example

<div class="c-block -large">
    <div class="c-block_layout o-layout">
        <div class="o-layout_item u-1/2@from-medium">
            <div class="c-block_heading o-h -medium">Heading</div>
        </div>
        <div class="o-layout_item u-1/2@from-medium">
           <a class="c-block_button o-button -outline" href="#">Button</a>
        </div>
    </div>
</div>
.c-block {
    &.-large {
        padding: rem(60px);
    }
}

.c-block_heading {
    @media (max-width: $to-medium) {
        .c-block.-large & {
            margin-bottom: rem(40px);
        } 
    }
}

Scripts

modularJS is a small framework we use on top of ES modules. It compiles with Rollup and Babel.

Why

  • Automatically init visible modules.
  • Easily call other modules methods.
  • Quickly set scoped events with delegation.
  • Simply select DOM elements scoped in their module.

source

Example

<div data-module-example>
    <div data-example="main">
        <h2>Example</h2>
    </div>
    <button data-example="load">More</button>
</div>
import { module } from 'modujs';

export default class extends module {
    constructor(m) {
        super(m);

        this.events = {
            click: {
                load: 'loadMore'
            }
        }
    }

    loadMore() {
        this.$('main').classList.add('is-loading');
    }
}

Learn more

Page transitions

modularLoad is used for page transitions and lazy loading.

Example

<nav>
    <a href="/">Home</a>
    <a href="/page" data-load="transitionName">Page</a>
</nav>
<div data-load-container>
    <img data-load-src="assets/images/hello.jpg">
</div>
import modularLoad from 'modularload';

this.load = new modularLoad({
    enterDelay: 300,
    transitions: {
        transitionName: {
            enterDelay: 450
        }
    }
});

Learn more

Scroll detection

Locomotive Scroll is used for elements in viewport detection and smooth scrolling with parallax.

Example

<div data-module-scroll>
    <div data-scroll>Trigger</div>
    <div data-scroll data-scroll-speed="1">Parallax</div>
</div>
import LocomotiveScroll from 'locomotive-scroll';

this.scroll = new LocomotiveScroll({
    el: this.el,
    smooth: true
});

Learn more

主要指標

概覽
名稱與所有者locomotivemtl/locomotive-boilerplate
主編程語言JavaScript
編程語言HTML (語言數: 3)
平台
許可證MIT License
所有者活动
創建於2014-05-30 21:40:37
推送於2025-01-07 18:17:43
最后一次提交2025-01-06 12:12:38
發布數0
用户参与
星數481
關注者數26
派生數68
提交數737
已啟用問題?
問題數26
打開的問題數3
拉請求數111
打開的拉請求數11
關閉的拉請求數38
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?