JavaScript code to implement small blocks with random colors _ basic knowledge-js tutorial

Source: Internet
Author: User
This article mainly uses js Code to implement random color blocks. For more information, see the following code: Random color blocks implemented by js, code directly.

/**/Js comment deleted     
    
    Koringz   
      

* {-Webkit-box-sizing: border-box;-moz-box-sizing: border-box;} html {font-size: px;-webkit-tap-highlight-color: transparent;} body {margin:; padding:; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: px; line-height :.; color: #; background-color: rgba (,,,.);}. container {overflow: visible ;}. main {position: relative; width: %; height: px; margin: auto ;}. colorful {overflow: visible; width: %; height: % ;}. colorful> a {float: left; display: block; width: px; height: px; zoom :;}. colorful> a: hover {-webkit-animation: infinite s release-in-out start-roll;-moz-animation: infinite s release-in-out start-roll; animation: infinite s release-in-out start-roll;} @-webkit-keyframes start-roll {%{-webkit-transform: rotate (deg ); /* chrome */-moz-transform: rotate (deg);/* Firefox */-ms-transform: rotate (deg);/* IE */transform: rotate (deg);-webkit-transition: opacity. s linear; transition: opacity. s linear; opacity :.; filter: alpha (opacity =); zoom :;%{-webkit-transform: rotate (deg);/* chrome */-moz-transform: rotate (deg ); /* Firefox */-ms-transform: rotate (deg);/* IE */transform: rotate (deg);-webkit-transition: opacity s linear; transition: opacity s linear; opacity:; filter: alpha (opacity =); zoom :;%{-webkit-transform: rotate (deg ); /* chrome */-moz-transform: rotate (deg);/* Firefox */-ms-transform: rotate (deg);/* IE */transform: rotate (deg);-webkit-transition: opacity. s linear; transition: opacity. s linear; opacity :.; filter: alpha (opacity =); zoom :;}@-moz-keyframes start-roll {%{-webkit-transform: rotate (deg ); /* chrome */-moz-transform: rotate (deg);/* Firefox */-ms-transform: rotate (deg);/* IE */transform: rotate (deg);-webkit-transition: opacity. s linear; transition: opacity. s linear; opacity :.; filter: alpha (opacity =) ;}%{-webkit-transform: rotate (deg);/* chrome */-moz-transform: rotate (deg ); /* Firefox */-ms-transform: rotate (deg);/* IE */transform: rotate (deg);-webkit-transition: opacity s linear; transition: opacity s linear; opacity :.; filter: alpha (opacity =) ;}%{-webkit-transform: rotate (deg);/* chrome */-moz-transform: rotate (deg ); /* Firefox */-ms-transform: rotate (deg);/* IE */transform: rotate (deg);-webkit-transition: opacity. s linear; transition: opacity. s linear; opacity :.; filter: alpha (opacity =) ;}@ keyframes start-roll {%{-webkit-transform: rotate (deg);/* chrome */-moz-transform: rotate (deg);/* Firefox */-ms-transform: rotate (deg);/* IE */transform: rotate (deg);-webkit-transition: opacity. s linear; transition: opacity. s linear; opacity :.; filter: alpha (opacity =) ;}%{-webkit-transform: rotate (deg);/* chrome */-moz-transform: rotate (deg ); /* Firefox */-ms-transform: rotate (deg);/* IE */transform: rotate (deg);-webkit-transition: opacity s linear; transition: opacity s linear; opacity :.; filter: alpha (opacity =) ;}%{-webkit-transform: rotate (deg);/* chrome */-moz-transform: rotate (deg ); /* Firefox */-ms-transform: rotate (deg);/* IE */transform: rotate (deg);-webkit-transition: opacity. s linear; transition: opacity. s linear; opacity :.; filter: alpha (opacity =) ;}( function (window) {var document = variable Doc ument; function on (elem, evolap, eventhd) {var onevsp2 = 'on' + evsp2; elem [onevsp2] = eventhd;} function grc () {var val = [], I =; while (++ I <=) {val. push (Math. floor (Math. random () *);} return 'rgb ('+ val. join () + ')';} function fbc () {var el = document. querySelectorAll ('. colorful ') [], total = Math. floor (el. offsetWidth/) * Math. floor (el. offsetHeight/), df = document. createDocumentFragment (), a; while (total -->) {a = document. createElement ('A');. style. backgroundColor = grc (); df. appendChild (a);} el. appendChild (df) ;}on (window, 'load', function () {fbc () ;}) (window)

The above code is to use JavaScript to implement all the content of the random color small square. If you need it, you can refer to it.

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.