基于raphael 的图形变化(jQuery)


该版本功能和 基于raphael 的图形变化(proptotype)相同。使用了jQuery.js;raphael.js
jqDnR.js
/*
* jqDnR - Minimalistic Drag'n'Resize for jQuery.
*
* Copyright (c) 2007 Brice Burgess , http://www.iceburg.net
* Licensed under the MIT License:
* http://www.opensource.org/licenses/mit-license.php
*
* $Version: 2007.08.19 +r2
*/

(function($){
$.fn.jqDrag=function(h){return i(this,h,'d');};
$.fn.jqResize=function(h){return i(this,h,'r');};
$.jqDnR={dnr:{},e:0,
drag:function(v){
if(M.k == 'd')E.css({left:M.X+v.pageX-M.pX,top:M.Y+v.pageY-M.pY});
else E.css({width:Math.max(v.pageX-M.pX+M.W,0),height:Math.max(v.pageY-M.pY+M.H,0)});
return false;},
stop:function(){E.css('opacity',M.o);$().unbind('mousemove',J.drag).unbind('mouseup',J.stop);}
};
var J=$.jqDnR,M=J.dnr,E=J.e,
i=function(e,h,k){return e.each(function(){h=(h)?$(h,e):e;
h.bind('mousedown',{e:e,k:k},function(v){var d=v.data,p={};E=d.e;
// attempt utilization of dimensions plugin to fix IE issues
if(E.css('position') != 'relative'){try{E.position(p);}catch(e){}}
M={X:p.left||f('left')||0,Y:p.top||f('top')||0,W:f('width')||E[0].scrollWidth||0,H:f('height')||E[0].scrollHeight||0,pX:v.pageX,pY:v.pageY,k:d.k,o:E.css('opacity')};
E.css({opacity:0.8});$().mousemove($.jqDnR.drag).mouseup($.jqDnR.stop);
return false;
});
});},
f=function(k){return parseInt(E.css(k))||false;};
})(jQuery);

image.js
$(document).ready(function() {
var canvans_width = 300,
canvans_height = 200,
image_width = $("#rImg").width(),
image_height = $("#rImg").height(),
ration_r = image_width/image_height;

$("#selectArea").css({
background:"#888888",
width:canvans_width,
height:canvans_height
});

var paper = Raphael("selectArea", canvans_width, canvans_height),
image = paper.image("./image/GG.bmp", 0, 0, image_width, image_height);

$("#ok").click(function(){
paper.setSize($("#selectArea").width(), $("#selectArea").height());
pic_select = $("#picSelect").val();
degree = $("#degree").val();

if(pic_select=="customize"){
image.attr({
width:$("#selectArea").width(),
height:$("#selectArea").height()
});
}
if(pic_select=="actual size"){
image.attr({
width:image_width,
height:image_height
});
}
if(pic_select=="fit image"){
var ration = $("#selectArea").width()/$("#selectArea").height();
if(ration_r > ration){
image.attr({
width:$("#selectArea").width(),
height:$("#selectArea").width()/ration_r
});
}
else{
image.attr({
width:$("#selectArea").height()*ration_r,
height:$("#selectArea").height()
});
}
}
if(pic_select=="fit width"){
image.attr({
width:$("#selectArea").width(),
height:$("#selectArea").width()/ration_r
});
}
if(pic_select=="fit height"){
image.attr({
width:$("#selectArea").height()*ration_r,
height:$("#selectArea").height()
});
}
image.rotate(degree);
});
});


html代码:

你可能感兴趣的:(jquery)