Zi 字媒體
2017-07-25T20:27:27+00:00
Jcrop(github) 是一個裁切圖片介面的 jQuery plugin.
安裝
可以直接下載檔案或透過 bower 安裝
bower install Jcrop
使用範例
HTML
javascript
$(function () {
$('.crop-img').Jcrop({
onChange: showCoords,
onSelect: showCoords,
onRelease: clearCoords,
aspectRatio: 1
});
var showCoords = function(c) {
// 圖片縮放比例()
var narrow_ratio = 1;
// 座標
var crop_x1 = c.x * narrow_ratio;
var crop_y1 = c.y * narrow_ratio;
var crop_x2 = c.x2 * narrow_ratio;
var crop_y2 = c.y2 * narrow_ratio;
var crop_w = c.w * narrow_ratio;
var crop_h = c.h * narrow_ratio;
// 確認不會超出原圖大小
crop_w = (crop_w > src_w) ? src_w : crop_w;
crop_h = (crop_h > src_h) ? src_h : crop_h;
if (crop_w !== crop_h && crop_h > crop_w) {
crop_h = crop_w;
} else if (crop_w !== crop_h && crop_w > crop_h) {
crop_w = crop_h;
}
// Do Something
};
var clearCoords = function() {
// Clear
};
});
Categories: jQuery
分類
Android
AngularJS
API Blueprint
Chrome
Database
MySQL
DataStructure
Docker
Editor
Vim
Firefox
Git
GitLab
Google API
Hadoop
Language
Go
Java
JavaScript
jQuery
jQueryChart
Node.js
Vue
PHP
Laravel
ZendFramework
Python
Mac
Network
Cisco
DLink
Juniper
Oauth
Server
Apache
Share
Unix
FreeBSD
Linux
WebDesign
Bootstrap
CSS
HTML
Wordpress
Search
搜尋關鍵字:
寫了
5860316篇文章,獲得
23313次喜歡