Javascript Articles - Page 438 of 534

Rotate HTML5 Canvas around the current origin

Krantik Chavan
Updated on 25-Jun-2020 07:37:37

562 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

HTML5 Audio to Play Randomly

Nishtha Thakur
Updated on 25-Jun-2020 07:38:46

455 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); }

Perform basic HTML5 Canvas animation

Arjun Thakur
Updated on 25-Jun-2020 07:38:10

349 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

cache.manifest works for the first time then fails in HTML

Smita Kapse
Updated on 25-Jun-2020 07:39:31

101 Views

Add the following in the bottom −NETWORK: *Set the version number of the manifest in the URL with the path.In addition, set −CACHE MANIFEST #rev ?v = 42 /css/style.css?v = 20 /js/myscript.js?v = 20

HTML5 Geolocation in Safari 5

George John
Updated on 25-Jun-2020 07:40:03

1K+ Views

HTML5 Geolocation API lets you share your location with your favorite web sites. A JavaScript can capture your latitude and longitude, can be sent to backend web server, and do fancy location-aware things like finding local businesses or showing your location on a map.ExampleLet us see how to get the current position −                    function showLocation(position) {             var latitude = position.coords.latitude;             var longitude = position.coords.longitude;             alert("Latitude : " + latitude + " ... Read More

HTML5+CSS3 Framework like BluePrint/960gs?

Arjun Thakur
Updated on 25-Jun-2020 07:23:57

143 Views

You can use the BluePrint/960gs framework or any of the following −52frameworkSusy        52framework (Refer)The framework that provides −CSS3 gradients, multiple shadows, and other amazing properties.CSS3 selectors with support for IE.New and improved HTML5 video support with vimeo like skinA completely new Form Framework with HTML5 Validation (via javascript)Susy (Refer)A lightweight grid-layout framework for Sass. This is designed to clarify responsive grid layouts. Use Susy with floats, flexbox, tables, etc.

Convert coordinates to a place name with HTML5

Anvi Jain
Updated on 25-Jun-2020 07:22:53

344 Views

For this, use Google Maps API to perform reverse geocoding.Geocoding refers to translating a human-readable address into a location on a map.The process of doing the converse, translating a location on the map into a human-readable address, is known as reverse geocoding.ExampleLet us see an example to set latitude and longitude −function initMap() {    var map = new google.maps.Map(document.getElementById('map'), {       zoom: 8,       center: {lat: 20.502, lng: -22.765}    }); }The reverse geocoder will match countries, provinces, cities and neighborhoods, street addresses, and postal codes.

Do any browsers yet support HTML5's checkValidity() method?

Nitya Raut
Updated on 25-Jun-2020 07:24:36

197 Views

Yes, the checkValidity() works in Google Chrome and Opera as well. This works as well −Example                    .valid {             color: #0B7866;          }          .invalid {             color: #0B6877;          }                            function check(input) {             var out = document.getElementById('result');             if (input.validity) {                if (input.validity.valid === true) {                   out.innerHTML = "" + input.id +                   " valid";                   } else {                   out.innerHTML = "" + input.id +                  " not valid";                }             }             console.log(input.checkValidity());          };                      Minimum:                                

DOMException Failed to load because no supported source was found

karthikeya Boyini
Updated on 25-Jun-2020 07:26:12

3K+ Views

It can be a Cross-Origin Resource Sharing (CORS) issue.video.crossOrigin = 'anonymous';To enable cross-origin resource sharing, use the following. It allows the images to pass the HTTP header with an image response.Access-Control-Allow-Origin: *You can also use the HTML() method −$('#audio').html('');

What is composition in HTML5 Canvas?

Arjun Thakur
Updated on 28-Jan-2020 06:04:08

336 Views

HTML5 canvas provides compositing attribute globalCompositeOperation that affect all the drawing operations.ExampleWe can draw new shapes behind existing shapes and mask off certain areas, clear sections from the canvas using globalCompositeOperation attribute as shown below in the example.                    var compositeTypes = [             'source-over','source-in','source-out','source-atop',             'destination-over','destination-in','destination-out',             'destination-atop','lighter','darker','copy','xor'          ];          function drawShape(){             for (i=0;i

Advertisements