JavaScript code for simple implementation of DIV rounded corners _ Javascript tutorial

Source: Internet
Author: User
JAVASCRIPT: JavaScript code for DIV rounded corners. Javascript tutorial

This program is an open source javascript code implementation used to create DIV rounded corners. The effect is the same as that of image rounded corners. it is simple and easy to use. Different radius rounded corners can be achieved without modifying any image ....
With this code, you can customize your own DIV, which is no longer a square, and can fully implement a circular and personalized DIV.

Usage instructions:

The following example uses a DIV with a 20-pixel rounded corner.

------------------------------
Decompress the downloaded file and upload it to your site. Copy the following code and paste it into the top part of your web page. If you save the file to a directory outside the web page

Modify the src value in the code anywhere.
=== Code:
<Script type = "text/javascript" src = "rounded_corners.js"> 

------------------------------ B
Then create a DIV. If you already have a DIV that uses rounded corners, you only need to give this DIV an id.
=== Code:
<DIV id = "myDiv">

------------------------------ C
Finally, we need to add a piece of javascript to pre-load. Add the following code in the top part of your webpage:

The following is a reference clip:


Window. onload = function ()
{
Settings = {
Tl: {radius: 20 },
Tr: {radius: 20 },
Bl: {radius: 20 },
Br: {radius: 20 },
AntiAlias: true,
AutoPad: false
}

Var divObj = document. getElementById ("myDiv ");

Var cornersObj = new curvyCorners (settings, divObj );
CornersObj. applyCornersToAll ();
}

Script

Radius indicates the radius. The larger the value, the larger the rounded corner.
------------------------------------ D
Now you can run it.

----------------------------------- PS:
* ******* If you want to create an odd rounded corner, you can set different radius for each corner.
For example:
The following is a reference clip:
Settings = {
Tl: {radius: 20 },
Tr: {radius: 40 },
Bl: {radius: 60 },
Br: {radius: 80 },
AntiAlias: true,
AutoPad: false
}
Or:
Settings = {
Tl: {radius: 20 },
Tr: false,
Bl: false,
Br: {radius: 80 },
AntiAlias: true,
AutoPad: false
}


Tip: tl-upper left corner tr = upper right corner bl = lower left corner br = lower right corner

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.