Javascript Articles

Page 364 of 534

Perform basic HTML5 Canvas animation

Arjun Thakur
Arjun Thakur
Updated on 15-Mar-2026 362 Views

HTML5 canvas provides the necessary methods to draw and manipulate graphics dynamically. Combined with JavaScript, we can create smooth animations by continuously redrawing the canvas content at regular intervals. How Canvas Animation Works Canvas animation involves three key steps: Clear the canvas - Remove previous frame content Draw new content - Render the updated animation frame Repeat - Use timers to create continuous motion Basic Rotating Image Animation Here's a complete example that rotates an image around the canvas center: ...

Read More

HTML5 Audio to Play Randomly

Nishtha Thakur
Nishtha Thakur
Updated on 15-Mar-2026 493 Views

HTML5 Audio API allows you to play audio files randomly by combining JavaScript arrays with the Math.random() method. This technique is useful for music players, games, or any application requiring random audio playback. Setting Up the Audio Collection First, initialize an array of audio sources. Each song should be added to the collection using the init() function: init ([ 'http://demo.com/songs/song1.mp3', 'http://demo.com/songs/song2.mp3', 'http://demo.com/songs/song3.mp3' ]); Complete Random Audio Player Implementation Here's a complete example that creates audio objects and implements random playback: ...

Read More

How to match strings that aren't entirely digits in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 115 Views

In JavaScript, you can use regular expressions to match strings that contain non-digit characters. This is useful when parsing complex data strings where you need to identify values that aren't purely numeric. Problem Statement Consider this complex string containing various data types: studentId:"100001",studentName:"John Smith",isTopper:true,uniqueId:10001J-10001,marks:78,newId:"4678" We want to extract values that contain characters other than digits, excluding boolean values and null. Using Regular Expression The following regular expression matches strings that aren't entirely digits: var regularExpression = /(?

Read More

Rotate HTML5 Canvas around the current origin

Krantik Chavan
Krantik Chavan
Updated on 15-Mar-2026 575 Views

HTML5 canvas provides the rotate(angle) method which rotates the canvas around the current origin point. This method is essential for creating rotated graphics and animations. Syntax context.rotate(angle); Parameters The method takes one parameter: angle: The rotation angle in radians (clockwise direction) To convert degrees to radians, use: radians = degrees * (Math.PI / 180) Basic Rotation Example Here's a simple example showing how to rotate a rectangle: canvas { ...

Read More

How to combine two arrays into an array of objects in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 3K+ Views

Combining two arrays into an array of objects is a common task in JavaScript. This allows you to pair corresponding elements from both arrays into structured data. Using map() with Object Creation The map() method creates a new array by transforming each element. We can use it to combine arrays into objects: var firstArray = ['John', 'David', 'Bob']; var secondArray = ['Mike', 'Sam', 'Carol']; var arrayOfObjects = firstArray.map(function(value, index) { return { first: value, second: ...

Read More

CSS only Animate - Draw Circle with border-radius and transparent background

Arjun Thakur
Arjun Thakur
Updated on 15-Mar-2026 838 Views

CSS animations can create impressive visual effects, including drawing animated circles with transparent backgrounds. This technique uses border-radius and keyframe animations to create a smooth circle-drawing effect. Basic Circle Structure The animation uses multiple div elements to create the drawing effect. The main container holds two half-circles that rotate to simulate drawing: CSS Animation Styles The CSS creates the drawing effect using transforms, opacity changes, and border properties: body { ...

Read More

Geolocation HTML5 enableHighAccuracy True, False or What?

Ankith Reddy
Ankith Reddy
Updated on 15-Mar-2026 394 Views

The enableHighAccuracy property in HTML5 Geolocation API controls whether the device should use high-precision GPS or faster network-based location services. Syntax navigator.geolocation.getCurrentPosition( successCallback, errorCallback, { enableHighAccuracy: true, // or false timeout: 10000, maximumAge: 0 } ); enableHighAccuracy: true When set to true, requests the most accurate position possible, typically using GPS: ...

Read More

Can JavaScript parent and child classes have a method with the same name?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 1K+ Views

Yes, JavaScript parent and child classes can have methods with the same name. This concept is called method overriding, where the child class provides its own implementation of a method that already exists in the parent class. Method Overriding Example class Parent { constructor(parentValue) { this.parentValue = parentValue; } // Parent class method showValues() { console.log("The parent method is called....."); ...

Read More

How to play HTML blocks one by one with no pops and clicks?

Nancy Den
Nancy Den
Updated on 15-Mar-2026 131 Views

To play HTML audio blocks sequentially without gaps or clicks, use the onended event to chain audio playback seamlessly. HTML Structure First, set up multiple audio elements with unique IDs: Basic Sequential Playback Use the onended event to automatically play the next audio when the current one finishes: var one = document.getElementById('one'); one.onended = function() { ...

Read More

Remove values in an array by comparing the items 0th index in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 304 Views

When working with arrays of sub-arrays, you may need to remove duplicates based on the first element (0th index) of each sub-array. This is common when dealing with data like subject-marks pairs where you want only unique subjects. Let's say the following is our array: var subjectNameAlongWithMarks = [ ["JavaScript", 78], ["Java", 56], ["JavaScript", 58], ["MySQL", 77], ["MongoDB", 75], ["Java", 98] ]; console.log("Original array:", subjectNameAlongWithMarks); Original array: [ ...

Read More
Showing 3631–3640 of 5,340 articles
« Prev 1 362 363 364 365 366 534 Next »
Advertisements