Share 5 interesting JavaScript code snippets

Source: Internet
Author: User

Many people think that programming languages are only used for work, and there is no pleasure. In fact, as long as we make full use of our whimsy, there is also an interesting aspect of rigid things. This article tells you that using JavaScript can do many interesting things. Copy the following code to the address bar and press enter to run it.

1. Web-based shooting games

This game can be played on any web page. paste the following code into the address bar and press Enter. Press the Space key for shooting. The W key can be pushed forward, and the, D keys or arrow keys can change the shooting direction.

Copy to ClipboardReference: [www.bkjia.com] javascript: var % 20 s % 20 = % 20document. createElement ('script'); s. type = 'text/javascript '; document. body. appendChild (s); s. src = 'HTTP: // erkie.github.com/asteroids.min.js'?void (0 );

2. Let the picture fly

After you paste the following code into the address bar of the browser and press Enter, all the images on the current webpage will be moved.

Copy to ClipboardReference: [www.bkjia.com] javascript: R = 0; x1 =. 1; y1 =. 05; x2 =. 25; y2 =. 24; x3 = 1.6; y3 =. 24; x4 = 300; y4 = 200; x5 = 300; y5 = 200; var DI = document. getElementsByTagName ("img"); DIL = DI. length; function A () {for (I = 0; I <DIL; I ++) {DIS = DI [I]. style; DIS. position = 'absolute '; DIS. left = Math. sin (R * x1 + I * x2 + x3) * x4 + x5 + "px"; DIS. top = Math. cos (R * y1 + I * y2 + y3) * y4 + y5 + "px"} R ++} tag = setInterval ('a () ', 5); document. onmousedown = function () {clearInterval (tag); for (I = 0; I <DIL; I ++) {DI [I]. style. position = "static" ;}}; void (0)

3. Make the webpage editable

This JavaScript code allows you to modify any webpage in real time. In Firefox, you can even save the modified webpage. For web designers, this function can help improve the page effect.

Copy to ClipboardReference content: [www.bkjia.com] javascript: document. body. contentEditable = 'true'; document. designMode = 'on'; void (0 );

4. Shake the browser

Changing the size of the browser window to the normal mode may have the best half screen effect. Paste the following code to the address bar and press Enter (it seems that only IE works ).

Copy to ClipboardReference: [www.bkjia.com] javascript: function Shw (n) {if (self. moveBy) {for (I = 35; I> 0; I --) {for (j = n; j> 0; j --) {self. moveBy (1, I); self. moveBy (I, 0); self. moveBy (0,-I); self. moveBy (-I, 0) ;}}} Shw (6 );

5. Address Bar Calculator

Haha, I never thought of it before. The address bar is a calculator.

Copy to ClipboardReference: [www.bkjia.com] javascript: alert (4 + 5 + 6 + 7 + (3*10 ));

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.