Code Monkey home page Code Monkey logo

eyeglass-spriting's Introduction

eyeglass spriting API

For basic usage, check out the eyeglass spriting example project.


sprite-map()

sprite-map($name, $layout, $paths...);

Generates a sprite map image and returns a Sass map containing information about individual sprites, which can be passed into other spriting functions. It can take multiple sprite sources, which can be paths or glob patterns. PNG, JPG, and GIF files can be made into sprites. Sprites are named using their original asset source paths. Note that sprite-map() does not actually generate the sprite map image.

For example, given the following assets directory structure:

|-- module-a
    |--icon-home.png
|-- module-b
    |--icons
        |--icon-back.png
        |--icon-forward.png
        |--icon-notifications.png
	            .
	            .
	            .

You might generate spritemap data using the following:

$icon-sprite-map: sprite-map($name: "icons", $layout: sprite-layout(horizontal, (spacing: 5px; alignment: bottom)), "module-a/icon-home.png", "module-b/icons/*");

$icon-sprite-map is now a Sass map which can be passed into the other spriting functions to get information about your sprites.


sprite-layout()

sprite-layout(($strategy), (spacing : 5px, alignment: $alignment));

Returns a map of sprite layout settings which can be passed directly into sprite-map(). It is recommended that you pass the output of sprite-layout() into sprite-map(), rather than generating your own layout.

Possible strategies and corresponding alignments are:

"vertical" - alignment "left" or "right"

"horizontal" - alignment "top" or "bottom"

"diagonal" - no alignment needed; spacing does not apply

If the alignment is invalid for the given strategy, sprite-layout() will return either a vertical-left or horizontal-top layout by default. If the strategy is invalid, sprite-layout() will return a vertical-left layout by default. Spacing and alignment values are both optional.


sprite-list()

sprite-list($sprite-map);

Returns a list of the names of each sprite in the sprite map.


sprite-url()

sprite-url($sprite-map);

Generates the sprite map image, and returns the path to the constructed sprite map image.

For example,

sprite-url($icon-sprite-map);

might generate a sprite map image at assets/icons.png.


sprite-background() (mixin)

sprite-background($sprite-map, $repeat: no-repeat);

A mixin that sets the background image to the generated spritemap image, with an optional repeat argument. For example,

.icon-bg {
	@include sprite-background($icon-sprite-map);
}

Might compile to the following css:

.icon-bg {
	background: url("/assets/icon-sprite-map.png") no-repeat;
}

Also causes the sprite map image to be generated.


sprite-position() (mixin)

sprite-position($sprite-map, $sprite-name);

A mixin that sets the background position to the position of the given sprite. For example,

.icon-home {
	@include sprite-background($icon-sprite-map);
	@include sprite-position($icon-sprite-map, "icons/home.png");
}

Might compile to the following css:

.icon-home {
	background: url("/assets/icon-sprite-map.png");
	background-position: 50px 100px;
}

sprite-dimensions() (mixin)

sprite-dimensions($sprite-map, $sprite-name);

A mixin that sets the dimensions of the element to the dimensions of the given sprite. For example,

.icon-home {
	@include sprite-background($icon-sprite-map);
	@include sprite-position($icon-sprite-map, "icons/home.png");
	@include sprite-dimensions($icon-sprite-map, "icons/home.png");
}

Might compile to the following css:

.icon-home {
	background: url("/assets/icon-sprite-map.png");
	background-position: 50px 100px;
	width: 32px;
	height: 32px;
}

sprite-position() (function)

sprite-position($sprite-map, $sprite-name);

Returns the position for the given sprite name in the given sprite map, in a format that is suitable for use as a value to background-position:

background-position: sprite-position($icons-sprite-map, "icons/home.png");

Might generate something like:

background-position: 50px 100px;

sprite-position-x()

sprite-position-x($sprite-map, $sprite-name);

Returns the x coordinate of the sprite. $sprite-map is returned from sprite-map(), and $sprite-name is the original asset url of the sprite.


sprite-position-y()

sprite-position-y($sprite-map, $sprite-name);

Returns the y coordinate of the sprite. $sprite-map is returned from sprite-map(), and $sprite-name is the original asset url of the sprite.


sprite-width()

sprite-width($sprite-map, $sprite-name);

Returns the width of the sprite. $sprite-map is returned from sprite-map(), and $sprite-name is the original asset url of the sprite.


sprite-height()

sprite-height($sprite-map, $sprite-name);

Returns the height of the sprite. $sprite-map is returned from sprite-map(), and $sprite-name is the original asset url of the sprite.


sprite-map-width()

sprite-map-width($sprite-map);

Returns the total width of the spritemap.


sprite-map-height()

sprite-map-height($sprite-map);

Returns the total height of the spritemap.

eyeglass-spriting's People

Contributors

joannajw avatar

Watchers

Cher Scarlett avatar James Cloos avatar

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.