Front End Scripts Articles

Page 32 of 47

canvas.style.display = "block" not working in HTML5

karthikeya Boyini
karthikeya Boyini
Updated on 15-Mar-2026 327 Views

When working with HTML5 canvas elements, you might encounter issues where setting canvas.style.display = "block" doesn't work as expected. This usually happens due to timing issues, incorrect element selection, or CSS conflicts. Common Problem The most frequent issue occurs when trying to modify the canvas display style before the DOM is fully loaded or when the canvas element reference is incorrect. Show Canvas function showCanvas() { let canvas = document.getElementById("myCanvas"); canvas.style.display = "block"; console.log("Canvas display set to:", canvas.style.display); } ...

Read More

To "user-scalable=no" or not to "user-scalable=no" in HTML5

Rishi Rathor
Rishi Rathor
Updated on 15-Mar-2026 341 Views

The user-scalable=no viewport meta tag prevents users from zooming on mobile devices. While it creates app-like experiences, it raises important accessibility concerns that developers must consider. What is user-scalable=no? The user-scalable property is part of the viewport meta tag that controls whether users can zoom in and out on mobile devices. When to Use user-scalable=no Consider using user-scalable=no only when creating web applications that need to mimic native mobile app behavior: App-like Interface ...

Read More

Detect area of a PNG that is not transparent with HTML

Lakshmi Srinivas
Lakshmi Srinivas
Updated on 15-Mar-2026 581 Views

To detect the non-transparent area of a PNG image in HTML, you need to use the Canvas API to access pixel data and scan for opaque pixels. This technique is useful for cropping images, collision detection, or optimizing sprite sheets. How It Works The process involves loading the image onto a canvas, getting the pixel data as a buffer, and scanning for non-transparent pixels to find the bounding box: Load the PNG image onto a canvas element Get the 32-bit RGBA pixel data using getImageData() Scan from ...

Read More

Apply gravity between two or more objects in HTML5 Canvas

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

To apply gravity between two or more objects in HTML5 Canvas, you need to calculate the gravitational force between each pair of objects and update their velocities accordingly. Gravitational Force Formula The gravitational force between two objects is calculated using Newton's law of universal gravitation. In our simplified 2D canvas implementation, we use: F = G * (m1 * m2) / r² Where F is the force, G is the gravitational constant, m1 and m2 are the masses, and r is the distance between objects. Basic Gravity Calculation Here's how to calculate ...

Read More

HTML5 tag

Lakshmi Srinivas
Lakshmi Srinivas
Updated on 15-Mar-2026 303 Views

The HTML5 tag is used to create radial gradients in SVG graphics. It defines a smooth color transition that radiates from a center point outward in a circular pattern, making it perfect for creating lighting effects, shadows, and visual depth in SVG elements. Syntax Key Attributes cx, cy: Center point coordinates of the gradient (default: 50%) r: Radius of the gradient (default: 50%) fx, fy: Focal point coordinates for gradient focus gradientUnits: Coordinate system ("objectBoundingBox" or "userSpaceOnUse") Example: ...

Read More

Difference between Session Storage and Local Storage in HTML5

Daniol Thomas
Daniol Thomas
Updated on 15-Mar-2026 870 Views

HTML5 provides two web storage mechanisms: Session Storage and Local Storage. Both allow web applications to store data locally in the user's browser, but they differ in scope and persistence. Session Storage Session Storage is designed for scenarios where the user is carrying out a single transaction but could be carrying out multiple transactions in different windows at the same time. Data stored in Session Storage is only available for the duration of the page session. // Store data in Session Storage sessionStorage.setItem("username", "john_doe"); sessionStorage.setItem("theme", "dark"); // Retrieve data from Session Storage console.log("Username:", sessionStorage.getItem("username")); ...

Read More

How can I handle Server-Sent Events in HTML5?

karthikeya Boyini
karthikeya Boyini
Updated on 15-Mar-2026 219 Views

Server-Sent Events (SSE) in HTML5 allow web pages to receive automatic updates from a server. This creates a persistent connection where the server can push data to the client in real-time. What are Server-Sent Events? Server-Sent Events provide a way for a server to send data to a web page automatically. Unlike WebSockets, SSE is unidirectional - only the server can send data to the client. Creating an EventSource Connection Use the EventSource object to establish a connection to the server: Server-Sent Events Demo ...

Read More

How to send a cross-document message with HTML?

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

Cross-document messaging allows secure communication between different browsing contexts (windows, iframes, or tabs) using the postMessage() API, even when they have different origins. Syntax targetWindow.postMessage(message, targetOrigin); Parameters message − The data to send (string, object, or any serializable value) targetOrigin − The origin URL of the target window (use "*" for any origin, but specify for security) Example: Sending Message from Parent to Iframe Parent window HTML: Send Message to Iframe ...

Read More

Two way communication between the browsing contexts in HTML5

Rishi Rathor
Rishi Rathor
Updated on 15-Mar-2026 437 Views

Two-way communication between browsing contexts in HTML5 is achieved through Channel Messaging API. This allows secure communication between different origins, iframes, web workers, and windows. The MessageChannel creates two connected ports that can send messages to each other. When you create a MessageChannel, it internally generates two ports - one for sending data and another that gets forwarded to the target browsing context. Key Methods postMessage() − Posts the message through the channel start() − Starts listening for messages on the port close() − Closes the communication ports Basic Syntax // Create ...

Read More

Features detected by Modernizr

Jennifer Nicholas
Jennifer Nicholas
Updated on 15-Mar-2026 653 Views

Modernizr is a JavaScript library that detects HTML5 and CSS3 features in browsers. It provides both CSS classes and JavaScript properties to help developers create progressive enhancement strategies. How Feature Detection Works Modernizr adds CSS classes to the element and creates JavaScript properties on the Modernizr object. This allows you to apply styles or run scripts only when features are supported. // Check if canvas is supported if (Modernizr.canvas) { console.log("Canvas is supported!"); } else { console.log("Canvas not supported - provide fallback"); } Complete Feature ...

Read More
Showing 311–320 of 465 articles
« Prev 1 30 31 32 33 34 47 Next »
Advertisements