Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Javascript Articles
Page 364 of 534
Perform basic HTML5 Canvas animation
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 MoreHTML5 Audio to Play Randomly
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 MoreHow to match strings that aren't entirely digits in JavaScript?
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 MoreRotate HTML5 Canvas around the current origin
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 MoreHow to combine two arrays into an array of objects in JavaScript?
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 MoreCSS only Animate - Draw Circle with border-radius and transparent background
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 MoreGeolocation HTML5 enableHighAccuracy True, False or What?
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 MoreCan JavaScript parent and child classes have a method with the same name?
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 MoreHow to play HTML blocks one by one with no pops and clicks?
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 MoreRemove values in an array by comparing the items 0th index in JavaScript?
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