HTML5¼¼Êõ

HTML5±¾µØͼƬ²Ã¼ô²¢ÉÏ´« - QxQstar

×ÖºÅ+ ×÷ÕߣºH5Ö®¼Ò À´Ô´£ºH5Ö®¼Ò 2017-03-25 14:00 ÎÒÒªÆÀÂÛ( )

×î½ü×öÁËÒ»¸öÏîÄ¿£¬Õâ¸öÏîÄ¿ÖÐÐèҪʵÏÖµÄÒ»¸ö¹¦ÄÜÊÇ£ºÓû§×Ô¶¨ÒåÍ·Ïñ£¨Óû§ÔÚ±¾µØÑ¡ÔñÒ»ÕÅͼƬ£¬ÔÚ±¾µØ½«Í¼Æ¬²Ã¼ô³ÉÂú×ãϵͳҪÇó³ß´çµÄ´óС£©¡£Õâ¸ö¹¦ÄܵÄÐèÇóÊÇ£ºÍ·Ïñ×î³õ¼ôÇÐΪһ¸öÕý·½ÐΡ£Èç¹ûÑ¡ÔñµÄͼƬСÓڹ涨µÄÍ·ÏñÒªÇó³ß´ç£¬ÄÇôÕâÕûÕÅͼƬ¶¼»á×÷Ϊ

×î½ü×öÁËÒ»¸öÏîÄ¿£¬Õâ¸öÏîÄ¿ÖÐÐèҪʵÏÖµÄÒ»¸ö¹¦ÄÜÊÇ£ºÓû§×Ô¶¨ÒåÍ·Ïñ£¨Óû§ÔÚ±¾µØÑ¡ÔñÒ»ÕÅͼƬ£¬ÔÚ±¾µØ½«Í¼Æ¬²Ã¼ô³ÉÂú×ãϵͳҪÇó³ß´çµÄ´óС£©¡£Õâ¸ö¹¦ÄܵÄÐèÇóÊÇ£ºÍ·Ïñ×î³õ¼ôÇÐΪһ¸öÕý·½ÐΡ£Èç¹ûÑ¡ÔñµÄͼƬСÓڹ涨µÄÍ·ÏñÒªÇó³ß´ç£¬ÄÇôÕâÕûÕÅͼƬ¶¼»á×÷ΪͷÏñ¡£Èç¹û´óÓڹ涨µÄ³ß´ç£¬ÄÇôÓû§¿ÉÒÔÑ¡ÔñÒª²Ã¼ôµÄÇøÓò¡£Óû§µã»÷È·¶¨°´Å¥£¬¾Í½«²Ã¼ôµÃµ½µÄͼƬÊý¾Ý·¢Ë͵½·þÎñÆ÷£¬ÔÚºó¶Ë½«Í¼Æ¬Êý¾Ý±£´æ³ÉÒ»¸öÎļþ¡£

ÒªÍê³ÉÉÏÊö¹¦ÄÜ£¬Éæ¼°µ½µÄ֪ʶÓУºajax£¬canvasºÍhtml5ÖеÄfiles½Ó¿Ú¡£ÎÒ½«ÊµÏÖÕâ¸ö¹¦ÄܵĴúÂë·â×°µ½ÁË4¸öÄ£¿éÖУ¬·Ö±ðÊÇajax.js£¬preview.js£¬shear.jsºÍcustomerImg.js¡£

ajax.js:ÓÃÓÚ·¢ËÍajaxÇëÇó¡£

preview.js:ÓÃÓÚͼƬԤÀÀ

shear.js£ºÓÃÓڲüôͼƬ

customer.js:×Ô¶¨ÒåÍ·Ïñ¡£ÔÚÕâ¸öÄ£¿éÖÐÒ©ÒýÈëajax.js£¬preview.jsºÍshear.js

ÎÒʹÓÃwebpack½øÐдò°ü¡£ÎÒ»¹Ê¹ÓÃÁËjqueryºÍjquery-ui¡£

ÎÒ´ÓÕâ¸öÏîÄ¿ÖгéÀë³öÁËÕâ¸ö¹¦ÄÜ¡£ÏÂÃæÊÇÕâ¸ö¹¦ÄܵÄÏêϸ´úÂë¡£

1.HTML´úÂë

Ñ¡ÔñͼƬԤÀÀÈ·¶¨

2.CSS´úÂë

.clearfix:after{ content: ""; display: block; clear: both; height: 0; overflow: hidden; visibility: hidden; } img{
¡¡¡¡vertical-align: middle;
¡¡¡¡max-width:100%
} .m-warp{ width: 800px; } .item{ margin-top: 20px; } .col{ float: left; } .col-1{ position: relative; width: 450px; height: 450px; outline: 1px solid #333; } .preview{ display: inline-block; } .col-2{ width: 300px; margin-left: 50px; } label{ display: block; text-align: center; width: 100px; font-size: 16px; color: #fff; background-color: #888888; height: 30px; line-height: 30px; } .mask{ position: absolute; z-index: 1; top:0; left: 0; bottom: 0; right: 0; background-color: rgba(0,0,0,.4); } .cvsMove{ position: absolute; z-index: 2; outline: 2px dotted #333; cursor: move; display: none; }

ÓÐÁËcssºÍhtmlµÄÔËÐнá¹ûÈçÏ£º

3.js´úÂë customerImg.js

var $ = require('jquery'); var ajax = require('./ajax.js'); var preview = require('./preview.js'); var shear = require('./shear.js'); /** * ×Ô¶¨ÒåÍ·Ïñ * @constructor */ function CustomerImg() { this.isSupport = null; this.previewBox = null; this.warp = null; } /** * Èë¿Ú * @param warp ²Ù×÷ÇøÓò jquery½Úµã */ CustomerImg.prototype.start = function (warp) { var info,me,warpBox; me = this; this.isSupport = this.__isSupport(); if(!this.isSupport) { info = $('<p>ÄãµÄä¯ÀÀÆ÷²»Ö§³Ö×Ô¶¨ÒåÍ·Ïñ£¬¿É¸ü»»¸ß°æ±¾µÄä¯ÀÀÆ÷×Ô¶¨ÒåÍ·Ïñ</p>'); $('body').html(info); return this; } (warp && warp.length > 0){ this.warp = warp; }else{ return this; } //Ô¤ÀÀ preview.start(warp,shear.start.bind(shear,warp)); this.previewBox = warp.find('#preview'); //È·¶¨ warp .find('#submit') .unbind('click') .on('click',me.__submit.bind(me)); }; /** * Ìá½» * @private */ CustomerImg.prototype.__submit = function () { var cvsMove,data,fd; cvsMove = this.previewBox.find('#cvsMove'); data = cvsMove[0].toDataURL('image/jpg',1); fd = { 'customerImg':data }; ajax.upload(fd); }; /** * ÅжÏÊÇ·ñÖ§³Ö×Ô¶¨ÒåÍ·Ïñ * @returns {boolean} * @private */ CustomerImg.prototype.__isSupport = function () { var canvas,context; canvas= document.createElement('canvas'); if(typeof FileReader === 'function'&& canvas.getContext && canvas.toDataURL){ return true; }else{ return false; } }; var customerImg = new CustomerImg(); module.exports = customerImg;

preview.js

¡¡

1.±¾Õ¾×ñÑ­ÐÐÒµ¹æ·¶£¬ÈκÎתÔصĸå¼þ¶¼»áÃ÷È·±ê×¢×÷ÕߺÍÀ´Ô´£»2.±¾Õ¾µÄÔ­´´ÎÄÕ£¬ÇëתÔØʱÎñ±Ø×¢Ã÷ÎÄÕÂ×÷ÕߺÍÀ´Ô´£¬²»×ðÖØÔ­´´µÄÐÐΪÎÒÃǽ«×·¾¿ÔðÈΣ»3.×÷ÕßͶ¸å¿ÉÄܻᾭÎÒÃDZ༭Ð޸Ļò²¹³ä¡£

Ïà¹ØÎÄÕÂ
  • Html5ÓÎÏ·¿ò¼ÜcreateJS×é¼þ--EaselJS - Ò¶³¬Luka

    Html5ÓÎÏ·¿ò¼ÜcreateJS×é¼þ--EaselJS - Ò¶³¬Luka

    2017-03-22 12:01

  • HTML5ѧϰ±Ê¼Ç - С½©Ê¬

    HTML5ѧϰ±Ê¼Ç - С½©Ê¬

    2017-03-22 12:00

  • html5ÐÂÔö±êÇ© - ¼ÒסÈýÊ®ÈýÖØÌìÍâ

    html5ÐÂÔö±êÇ© - ¼ÒסÈýÊ®ÈýÖØÌìÍâ

    2017-03-22 11:01

  • HTML5ѧϰ±Ê¼ÇÒ»: ÈÏʶH5 - ÄÏÐİűÈ

    HTML5ѧϰ±Ê¼ÇÒ»: ÈÏʶH5 - ÄÏÐİűÈ

    2017-03-16 12:00

ÍøÓѵãÆÀ
Ê