portal html css js resource

basic.js 8.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. $(function(){
  2. //Ĭ��ͼ�������ʾ
  3. // cutImage($(".jcrop_w>img"));
  4. var _Jw = ($("#target").width() - 110) / 2 ,
  5. _Jh = ($("#target").height() - 110) / 2 ,
  6. _Jw2 = _Jw + 110,
  7. _Jh2 = _Jh + 110;
  8. $('#target').Jcrop({
  9. setSelect: [_Jw, _Jh, _Jw2, _Jh2],
  10. onChange: showPreview,
  11. onSelect: showPreview,
  12. bgFade: true,
  13. bgColor: "white",
  14. aspectRatio: 110/110,
  15. bgOpacity: .5
  16. });
  17. $("#idLeft").click(function(e){
  18. imgRotate(-90);
  19. return false;
  20. });
  21. $("#idRight").click(function(e){
  22. imgRotate(90);
  23. return false;
  24. });
  25. $("#idBig").click(function(e){
  26. imgToSize(20);
  27. return false;
  28. });
  29. $("#idSmall").click(function(e){
  30. imgToSize(-20);
  31. return false;
  32. });
  33. });
  34. //ͼƬ��ת
  35. function imgRotate(deg){
  36. var img1 = $(".jcrop_w>img"),
  37. _data = parseInt($(".jc-demo-box").attr("data"));
  38. if($.browser.version == 8.0 || $.browser.version == 7.0 || $.browser.version == 6.0 ){
  39. var sin = Math.sin(Math.PI / 180 * (_data + deg)), cos = Math.cos(Math.PI / 180 * (_data + deg));
  40. var _filter = "progid:DXImageTransform.Microsoft.Matrix(M11=" + cos + "," + "M12=" + (-sin)
  41. + ",M21=" + sin+ ",M22=" + cos + ",SizingMethod='auto expand')";
  42. img1.css({
  43. filter: _filter
  44. });
  45. $('.pre-1 img,.pre-2 img,.pre-3 img').css({
  46. filter: _filter
  47. });
  48. }else{
  49. var _deg = deg + _data;
  50. var _val = "rotate("+ _deg + "deg)";
  51. img1.css({
  52. "-webkit-transform": _val,
  53. "-moz-transform": _val,
  54. "-ms-transform": _val,
  55. "-o-transform": _val,
  56. "transform": _val
  57. });
  58. $('.pre-1 img,.pre-2 img,.pre-3 img').css({
  59. "-webkit-transform": _val,
  60. "-moz-transform": _val,
  61. "-ms-transform": _val,
  62. "-o-transform": _val,
  63. "transform": _val
  64. });
  65. }
  66. var fiw = $('.jcrop_w>img').width(),
  67. fih = $('.jcrop_w>img').height(),
  68. ow = Math.floor((395 - fiw) / 2),
  69. oh = Math.floor((340 - fih) / 2),
  70. cx = $("#small").position().left,
  71. cy = $("#small").position().top,
  72. rx = 200 / $("#small").width(),
  73. ry = 200 / $("#small").height(),
  74. rx1 = 50 / $("#small").width(),
  75. ry1 = 50 / $("#small").height(),
  76. rx2 = 26 / $("#small").width(),
  77. ry2 = 26 / $("#small").height();
  78. if($.browser.version == 8.0 || $.browser.version == 7.0 || $.browser.version == 6.0){
  79. pre_img2($('.pre-1 img'), rx, fih, ry, fiw, cx, cy, ow, oh);
  80. pre_img2($('.pre-2 img'), rx1, fih, ry1, fiw, cx, cy, ow, oh);
  81. pre_img2($('.pre-3 img'), rx2, fih, ry2, fiw, cx, cy, ow, oh);
  82. }else{
  83. pre_img2($('.pre-1 img'), rx, fiw, ry, fih, cx, cy, ow, oh);
  84. pre_img2($('.pre-2 img'), rx1, fiw, ry1, fih, cx, cy, ow, oh);
  85. pre_img2($('.pre-3 img'), rx2, fiw, ry2, fih, cx, cy, ow, oh);
  86. }
  87. $(".jcrop_w img").css({
  88. left: ow,
  89. top: oh
  90. });
  91. if( deg > 0){
  92. if(_data == 270){
  93. _data = 0;
  94. }else{
  95. _data = _data + 90;
  96. }
  97. }else{
  98. if(_data == 0){
  99. _data = 270;
  100. }else{
  101. _data = _data - 90;
  102. }
  103. }
  104. $("#d").val(_data);
  105. $(".jc-demo-box").attr("data", _data);
  106. }
  107. //�Ŵ���СͼƬ
  108. function imgToSize(size) {
  109. var iw = $('.jcrop_w>img').width(),
  110. ih = $('.jcrop_w>img').height(),
  111. _data = $(".jc-demo-box").attr("data"),
  112. _w = Math.round(iw + size),
  113. _h = Math.round(((iw + size) * ih) / iw);
  114. if(($.browser.version == 8.0 || $.browser.version == 7.0 || $.browser.version == 6.0) && (_data == 90 || _data == 270)){
  115. $('.jcrop_w>img').width(_h).height(_w);
  116. }else{
  117. $('.jcrop_w>img').width(_w).height(_h);
  118. }
  119. var fiw = $('.jcrop_w>img').width(),
  120. fih = $('.jcrop_w>img').height(),
  121. ow = (395 - fiw) / 2,
  122. oh = (340 - fih) / 2,
  123. cx = $("#small").position().left,
  124. cy = $("#small").position().top,
  125. rx = 200 / $("#small").width(),
  126. ry = 200 / $("#small").height(),
  127. rx1 = 50 / $("#small").width(),
  128. ry1 = 50 / $("#small").height(),
  129. rx2 = 26 / $("#small").width(),
  130. ry2 = 26 / $("#small").height();
  131. if(($.browser.version == 8.0 || $.browser.version == 7.0 || $.browser.version == 6.0) && (_data == 90 || _data == 270)){
  132. pre_img2($('.pre-1 img'), rx, fih, ry, fiw, cx, cy, ow, oh);
  133. pre_img2($('.pre-2 img'), rx1, fih, ry1, fiw, cx, cy, ow, oh);
  134. pre_img2($('.pre-3 img'), rx2, fih, ry2, fiw, cx, cy, ow, oh);
  135. }else{
  136. pre_img2($('.pre-1 img'), rx, fiw, ry, fih, cx, cy, ow, oh);
  137. pre_img2($('.pre-2 img'), rx1, fiw, ry1, fih, cx, cy, ow, oh);
  138. pre_img2($('.pre-3 img'), rx2, fiw, ry2, fih, cx, cy, ow, oh);
  139. }
  140. $(".jcrop_w img").css({
  141. left: ow,
  142. top: oh
  143. });
  144. };
  145. //
  146. function pre_img2(obj, rx, iw, ry, ih, cx, cy, ow, oh){
  147. obj.css({
  148. width: Math.round(rx * iw) + 'px',
  149. height: Math.round(ry * ih) + 'px'
  150. });
  151. if( cy >= oh && cx >= ow){
  152. obj.css({
  153. marginLeft: '-' + Math.round(rx * (cx - ow)) + 'px',
  154. marginTop: '-' + Math.round(ry * (cy - oh)) + 'px'
  155. });
  156. }else if( cy <= oh && cx >= ow){
  157. obj.css({
  158. marginLeft: "-" + Math.round(rx * (cx - ow)) + 'px',
  159. marginTop: Math.round(ry * (oh - cy)) + 'px'
  160. });
  161. }else if( cy >= oh && cx <= ow){
  162. obj.css({
  163. marginLeft: Math.round(rx * (ow - cx)) + 'px',
  164. marginTop: '-' + Math.round(ry * (cy - oh)) + 'px'
  165. });
  166. }else if( cy <= oh && cx <= ow){
  167. obj.css({
  168. marginLeft: Math.round(rx * (ow - cx)) + 'px',
  169. marginTop: Math.round(ry * (oh - cy)) + 'px'
  170. });
  171. }
  172. };
  173. //Ĭ��ͼ��λ��
  174. function cutImage(obj) {
  175. var w = 395,
  176. h = 340,
  177. iw = obj.width(),
  178. ih = obj.height();
  179. if(iw > w || ih > h){
  180. if(iw / ih > w / h){
  181. obj.css({
  182. width: w,
  183. height: w * ih / iw,
  184. top: (h - (w * ih / iw)) / 2,
  185. left: 0
  186. });
  187. }else{
  188. obj.css({
  189. height: h,
  190. width: h * iw / ih,
  191. top: 0,
  192. left: (w - (h * iw / ih)) / 2
  193. });
  194. }
  195. }else{
  196. obj.css({
  197. left: (w - iw) / 2,
  198. top: (h - ih ) / 2
  199. });
  200. }
  201. }
  202. function showPreview(c){
  203. var iw = $('.jcrop_w>img').width(),
  204. ih = $('.jcrop_w>img').height(),
  205. ow = (395 - iw) / 2,
  206. oh = (340 - ih) / 2,
  207. rx = 200 / c.w,
  208. ry = 200 / c.h,
  209. rx1 = 50 / c.w,
  210. ry1 = 50 / c.h,
  211. rx2 = 26 / c.w,
  212. ry2 = 26 / c.h,
  213. _data = $(".jc-demo-box").attr("data");
  214. if(($.browser.version == 8.0 || $.browser.version == 7.0 || $.browser.version == 6.0) && (_data == 90 || _data == 270)){
  215. pre_img2($('.pre-1 img'), rx, ih, ry, iw, c.x, c.y, ow, oh);
  216. pre_img2($('.pre-2 img'), rx1, ih, ry1, iw, c.x, c.y, ow, oh);
  217. pre_img2($('.pre-3 img'), rx2, ih, ry2, iw, c.x, c.y, ow, oh);
  218. }else{
  219. pre_img2($('.pre-1 img'), rx, iw, ry, ih, c.x, c.y, ow, oh);
  220. pre_img2($('.pre-2 img'), rx1, iw, ry1, ih, c.x, c.y, ow, oh);
  221. pre_img2($('.pre-3 img'), rx2, iw, ry2, ih, c.x, c.y, ow, oh);
  222. }
  223. $('#x').val(c.x);
  224. $('#y').val(c.y);
  225. $('#w').val(c.w);
  226. $('#h').val(c.h);
  227. }