JavaScript screenshot jquery Plugin imgareaselect use detailed _jquery

Source: Internet
Author: User

In order to enable users to customize their own avatar, you need to provide a screenshot of the upload function, the current many sites, especially SNS class sites provide such a function, very practical. There are two main forms of implementation, one is flash screenshots, the other is JavaScript screenshots, two methods each have a swing, about flash screenshots can refer to the Uchome program in the Avatar upload function, but this is not the topic I want to discuss, I am here mainly how to achieve JavaScript screenshots, using jquery imgareaselect plug-ins, easy to achieve a custom avatar [Avatar]javascript screenshot function.

One, prepare:
Two JS files
1,jquery.js Download: jquery.js
2,jquery.imgareaselect.js Download: Jquery.imgareaselect.js[imgareaselect-0.6.2.zip]

Second, use


Function Preview (IMG, selection) { 
var scaleX = 100/selection.width; 



//Dynamic small Avatar Gets the width, height, left border, and right frame of the currently selected box

$ (' #biuuu + div > img '). CSS ({ 
width:Math.round (ScaleX) + ' px ', 
height:Math.round (ScaleY *) + ' px ', C9/>marginleft: ' + math.round (ScaleX * selection.x1) + ' px ', 
margintop: '-' + math.round (ScaleY * selection.y1) + ' px ' 
}); 
 


Load Small Head

$ (document). Ready (function () { 
$ (' <div></div > ') 
. css ({ 
float: ' left ', 
position: ' relative ', 
overflow: ' Hidden ', 
width: ' 100px ' 
, Height: ' 100px ' 
}) 
. InsertAfter ($ (' #biuuu ')); 



//Initialization load

$ (window). Load (function () { 
$ (' #biuuu '). Imgareaselect ({aspectratio: ' 1:1 ', onselectchange:preview}); 


Third, call

<div class= "Container" > <p>  
</p> 


Using the JavaScript screenshot above to expand to achieve a lot of dynamic features, jquery provides Imgareaselect plug-in call is very simple, other relevant applications can refer to: Imgareaselect examples

Using the jquery plugin Imgareaselect to implement JavaScript screenshots is very simple, basically is a dynamic image display, get the source picture location and marquee size [width and height], easy to achieve JavaScript screenshots.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.