Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Javascript Articles - Page 539 of 671
138 Views
To listen to KeyDown events, use −if(keyIsPressed && keycode == somenumber) { doSomething(); }To capture KeyDown −var canvas1 = layer.getCanvas()._canvas; $(canvas1).attr('tabindex', 1); canvas1.focus(); $(canvas1).keydown(function (event) { console.log(event); });
717 Views
To choose, you need to define a wrapper function −function display ( file ) { if ( window.webkitURL ) { return window.webkitURL.createObjectURL( file ); } else if ( window.URL && window.URL.createObjectURL ) { return window.URL.display( file ); } else { return null; } }After that set it for cross-browser −var url = display( file );
325 Views
For Geolocation enableHighAccuracy, you need to set it to true −enableHighAccuracy: trueIf you still fail in getting the result i.e. handling the timeout error, then again try it withenableHighAccuracy: falseThe above would work on Android, Chrome, and Firefox as well.
746 Views
To draw a circle with transparent background and border-radius, use the following CSS −body { background: repeating-linear-gradient(45deg, white 0px, green 100px); height: 400px; background-size: 400px 400px; background-repeat: no-repeat; } html { height: 100%; } #box { position: absolute; width: 400px; height: 400px; border: solid blue 2px; animation: colors 5s infinite; } #demo { width: 50%; height: 100%; right: 0px; position: absolute; overflow: hidden; transform-origin: left center; animation: cliprotate 18s steps(2) infinite; -webkit-animation: cliprotate 18s steps(2) infinite; } .circlehalf { box-sizing: border-box; ... Read More
875 Views
HTML5 canvas provides two important methods to save and restore the canvas states.Canvas states are stored on a stack every time the save method is called, and the last saved state is returned from the stack every time the restore method is called.Sr.No.Method and Description1save()This method pushes the current state onto the stack..2restore()This method pops the top state on the stack, restoring the context to that state. ExampleYou can try ... Read More
517 Views
HTML5 canvas provides rotate(angle) method which is used to rotate the canvas around the current origin.This method only takes one parameter and that's the angle the canvas is rotated by. This is a clockwise rotation measured in radians.ExampleYou can try to run the following code to rotate HTML Canvas − #test { width: 100px; height:100px; margin: 0px auto; } ... Read More
407 Views
To play randomly, add the songs like this −init ([ 'http://demo.com/songs/song1.mp3, 'http://demo.com/songs/song2.mp3, 'http://demo.com/songs/song3.mp3 ]);Use the following to play randomly using Math.random −function displayRandom() { var audio = Math.floor(Math.random() * (collection.length)); audio = collection[audio]; audio.play(); setTimeout(loop,audio.duration*1000); }
313 Views
HTML5 canvas provides the necessary methods to draw an image and erase it completely. We can take JavaScript help to simulate good animation over an HTML5 canvas.ExampleYou can try to run the following code to perform basic HTML5 Canvas Animation − var pattern= new Image(); function animate(){ pattern.src = '/html5/images/pattern.jpg'; setInterval(drawShape, 100); } function drawShape(){ // get the canvas ... Read More

