项目作者: AlfonsoFilho

项目描述 :
Cross-browser clip-path polyfill
高级语言: JavaScript
项目地址: git://github.com/AlfonsoFilho/ClipPath.git
创建时间: 2014-08-18T18:35:32Z
项目社区:https://github.com/AlfonsoFilho/ClipPath

开源协议:MIT License

下载


ClipPath

Build Status
npm version

Cross-browser clip-path polyfill.

NOTE: currently only supports polygon values.

Installing

with npm:

  1. $ npm install clip-path --save

with yarn:

  1. $ yarn add clip-path

Usage

Vanilla javascript:

  1. ClipPath('.target', '5% 5%, 100% 0%, 100% 75%');

with jQuery:

  1. $('.target').ClipPath('5% 5%, 100% 0%, 100% 75%');

NOTE: for backward compatibility reasons, jquery implementation also accepts an object as an argument. In this case, a path property is expected. This alternative should be avoided since it is deprecated. (See also #4)

  1. // Using object instead string
  2. // @deprecated
  3. $('.image').ClipPath({path: '5% 5%, 100% 0%, 100% 75%, 75% 75%, 75% 100%, 50% 75%, 0% 75%'});

Or can use html element’s attribute to set clip points:

  1. <!-- In the html -->
  2. <img id='clipped' data-clip="5% 5%, 100% 0%, 100% 75%" src="https://unsplash.it/100/100/?random" />
  1. // In the javascript
  2. ClipPath('#clipped');

See example folder to view more usage cases.

API

  1. ClipPath(query_selector, polygon_value)

query_selector: string with css query selector. e.g.:#image img.test-class

polygon_value: string with polygon points in the format 'x y, x y, xy ...'.
e.g.:

  1. ClipPath('.target', '10px 10px, 15px 10px, 15px 15px, 10px 15px');

Test and Build

Clone the project and install dependencies:

  1. $ git clone git@github.com:AlfonsoFilho/ClipPath.git
  2. $ cd ClipPath && npm install

To test:

  1. $ npm test

To test and watch file changes

  1. $ npm run test:watch

To Build:

  1. $ npm start

or

  1. $ npm run build

To Do

  • Add support for circle, ellipse and inset;