天天躁日日躁狠狠躁AV麻豆-天天躁人人躁人人躁狂躁-天天澡夜夜澡人人澡-天天影视香色欲综合网-国产成人女人在线视频观看-国产成人女人视频在线观看

基于jquery.Jcrop的頭像編輯器

用過(guò)新浪微博的朋友對(duì)它的頭像編輯器都有印象吧.不過(guò)人家是用flash做的.
在一個(gè)項(xiàng)目中,也用到了同樣的東西,本來(lái)想直接用新浪微博的,但它有一部分請(qǐng)求路徑寫(xiě)到FLASH里面去了,所以只好放棄.
在網(wǎng)上找到了jquery.Jcrop,基本滿足了我的需求,但它只是簡(jiǎn)單的切割而已,還有縮略圖沒(méi)有生成.或許有很多人都需要這類(lèi)東西吧,于是我把它封裝起來(lái)了,方便其它朋友直接使用.
官方網(wǎng)址:http://deepliquid.com/content/Jcrop.html
上面有很多demo,有興趣的可以上去看看.
此文章中,封裝的JS如下:
復(fù)制代碼 代碼如下:
jQuery.UtrialAvatarCutter = function(config){
var h,w,x,y;
var os,oh,ow;
var api = null;
var sel = this;
var img_content_id = config.content;
var img_id = "img_"+(Math.random()+"").substr(3,8);
var purviews = new Array();
var select_width = null;
var select_height = null;
if(config.purviews){
for(i=0,c=config.purviews.length;i<c;++i){
purviews[purviews.length] = config.purviews[i];
}
}
check_thums_img = function(){
if(config.purviews){
for(i=0,c=config.purviews.length;i<c;++i){
if($('#'+config.purviews[i].id+" img").length==0){
$('#'+config.purviews[i].id).html("<img src='"+os+"'/>");
}else{
$('#'+config.purviews[i].id+" img").attr("src",os);
}
}
}
}
/*
* 重新加載圖片
*/
this.reload = function(img_url){
if(img_url!=null && img_url != ""){
os = img_url+"?"+Math.random();
$("#"+img_content_id).html("<img id='"+img_id+"' src='"+os+"'/>");
$("#"+img_id).bind("load",
function(){
check_thums_img();
sel.init();
}
);
}
}
$("#"+img_content_id+" img").attr("id",img_id);
var preview = function(c) {
if ( c.w == 0 || c.h == 0 ) {
api.setSelect([ x, y, x+w, y+h ]);
api.animateTo([ x, y, x+w, y+h ]);
return;
}
x = c.x;
y = c.y;
w = c.w;
h = c.h;
for(i=0,c=purviews.length;i<c;++i){
var purview = purviews[i];
var rx = purview.width / w;
var ry = purview.height / h;
$('#'+purview.id+" img").css({
width: Math.round(rx * ow) + 'px',
height: Math.round(ry * oh) + 'px',
marginLeft: '-' + Math.round(rx * x) + 'px',
marginTop: '-' + Math.round(ry * y) + 'px'
});
}
}
this.init = function(){
if(api!=null){
api.destroy();
}
os = $("#"+img_content_id+" img").attr("src");
if(os=="")
return;
check_thums_img();
for(i=0,c=purviews.length;i<c;++i){
var purview = purviews[i];
var purview_content = $("#"+purview.id);
purview_content.css({position: "relative", overflow:"hidden", height:purview.height+"px", width:purview.width+"px"});
}
oh = $('#'+img_id).height();
ow = $('#'+img_id).width();
select_width = config.selector.width;
select_height = config.selector.height;
select_width = Math.min(ow,select_width);
select_height = Math.min(oh,select_height);
x = ((ow - select_width) / 2);
y = ((oh - select_height) / 2);
//這是原Jcrop配置,修改此處可修改Jcrop的其它各種功能
api = $.Jcrop('#'+img_id,{
ASPectRatio: 1,
onChange: preview,
onSelect: preview
});
//設(shè)置選擇框默認(rèn)位置
api.animateTo([ x, y, x+select_width, y+select_height ]);
}
this.submit = function(){
return {w:w,h:h,x:x,y:y,s:os};
}
}

比較簡(jiǎn)單,不再多說(shuō)
應(yīng)用部分也非常簡(jiǎn)單
1. 導(dǎo)入必需的文件
代碼
復(fù)制代碼 代碼如下:
<LINK href="css/jquery.Jcrop.css" type="text/css" rel="Stylesheet" media="screen">
<script type="text/Javascript" src="js/jquery-1.3.2.min.js"></script>
<script type="text/Javascript" src="js/jquery.Jcrop.min.js"></script>
<script type="text/Javascript" src="js/jQuery.UtrialAvatarCutter.js"></script>

2. 定義原始圖片與縮略圖的容器
代碼
復(fù)制代碼 代碼如下:
<!--
原始圖
-->
<div id="picture_original">
<img src="http://static.youhuiduo.NET/Attatchment/72383/600X600/634030306987187500.jpg"/>
</div>
<!---
縮略圖
-->
<div id="picture_200"></div>
<div id="picture_50"></div>
<div id="picture_30"></div>

3. 配置
代碼
復(fù)制代碼 代碼如下:
var cutter = new jQuery.UtrialAvatarCutter(
{
//主圖片所在容器ID
content : "picture_original",
//縮略圖配置,ID:所在容器ID;width,height:縮略圖大小
purviews : [{id:"picture_200",width:200,height:200},{id:"picture_50",width:50,height:50},{id:"picture_30",width:30,height:30}],
//選擇器默認(rèn)大小
selector : {width:200,height:200}
}
);

4. 觸發(fā)
復(fù)制代碼 代碼如下:
$(window).load(function(){
cutter.init();
});

5. 如果是使用ajax上傳圖片的,可以使用cutter.reload(imgs_url)即時(shí)修改圖片路徑
文件打包下載 http://www.jb51.NET/jiaoben/24767.html

JavaScript技術(shù)基于jquery.Jcrop的頭像編輯器,轉(zhuǎn)載需保留來(lái)源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 免费光看午夜请高视频 | 在线亚洲视频无码天堂 | 亚洲精品乱码久久久久久直播 | 99午夜高清在线视频在观看 | 麻生希快播在线 | 老师别揉我胸啊嗯小说 | 国产精品久久久久激情影院 | 日韩精品真人荷官无码 | 99久久精品免费看国产一区二区 | 一本到道免费线观看 | 玛雅成人网 | 办公室日本肉丝OL在线 | 国内精品七七久久影院 | 果冻传媒独家原创在线观看 | 久久亚洲伊人 | 9久久99久久久精品齐齐综合色圆 | 麻豆AV福利AV久久AV | 国产成人小视频在线观看 | 黑丝制服影院 | yellow高清免费观看日本 | 国产精品亚洲AV色欲在线观看 | 用快播看黄的网站 | 精品视频在线播放 | 秀婷程仪公欲息肉婷在线观看 | 人妻体内射精一区二区 | 在线免费观看国产视频 | 草草久久久亚洲AV成人片 | 亚洲AV噜噜88 | 最近中文字幕MV免费高清视频8 | 欧美日韩午夜群交多人轮换 | 插骚妇好爽好骚 | 男女又黄又刺激B片免费网站 | 性色AV一区二区三区V视界影院 | 国产精品亚洲精品久久国语 | 久久理论片 | 国产人妻人伦精品久久无码 | 野花日本免费完整版高清版动漫 | 欧美在线看欧美视频免费 | 国产午夜精品一区二区 | 高清视频在线观看SEYEYE | 岛国大片在线播放免费 |