Programming Scripts Articles

Page 13 of 33

How to set a background image to be fixed with JavaScript DOM?

Rishi Raj
Rishi Raj
Updated on 15-Mar-2026 715 Views

To set a background image to be fixed in JavaScript, use the backgroundAttachment property. This CSS property controls whether the background image scrolls with the content or remains fixed in the viewport. Understanding backgroundAttachment The backgroundAttachment property accepts three values: "scroll" - Background scrolls with content (default) "fixed" - Background stays fixed relative to viewport "local" - Background scrolls with element's content Syntax element.style.backgroundAttachment = "fixed"; Example: Fixed Background Image This example demonstrates how to set a fixed background image that won't scroll with the page content: ...

Read More

How to set the starting position of a background image in JavaScript DOM?

Sharon Christine
Sharon Christine
Updated on 15-Mar-2026 570 Views

To set the starting position of a background image in JavaScript, use the backgroundPosition property. This property allows you to specify where the background image should be positioned within its container. Syntax element.style.backgroundPosition = "value"; Position Values The backgroundPosition property accepts various values: Keywords: top, bottom, left, right, center Percentages: 50% 25% (horizontal vertical) Pixels: 10px 20px (horizontal vertical) Mixed: left 50px, center top Example: Setting Background Position body { ...

Read More

Does HTML5 Canvas support Double Buffering?

Chandu yadav
Chandu yadav
Updated on 15-Mar-2026 690 Views

HTML5 Canvas doesn't have built-in double buffering, but you can implement it manually by creating a second off-screen canvas. This technique prevents flickering during complex animations by drawing to a hidden canvas first, then copying the complete frame to the visible canvas. What is Double Buffering? Double buffering uses two canvases: a visible "front buffer" and an invisible "back buffer". You draw your entire frame on the back buffer, then copy it to the front buffer in one operation. This eliminates the visual artifacts that occur when drawing directly to the visible canvas. Implementation Create an ...

Read More

Can you take a screenshot of the page using HTML5 Canvas?

George John
George John
Updated on 15-Mar-2026 732 Views

Html2Canvas is a JavaScript library that can take screenshots of web pages or specific elements. It doesn't capture actual screenshots but recreates the visual representation based on DOM information and CSS styles. How Html2Canvas Works The library reads the DOM structure and CSS properties to generate a canvas representation of the page. This approach works entirely in the browser without requiring server-side processing or special permissions. Basic Example Here's a complete example showing how to capture a screenshot of a specific container: ...

Read More

How to find the size of localStorage in HTML?

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

localStorage is used to persist information across multiple sessions. It has a maximum size of 5MB in most browsers and stores data as key-value pairs. Understanding localStorage Size Calculation Each character in localStorage is stored as UTF-16, taking 2 bytes. To calculate the size, we multiply the string length by 2 and convert to MB. Example: Calculate localStorage Size You can try to run the following code snippet to check the size allocated: localStorage Size Calculator localStorage Size Breakdown ...

Read More

How to draw an oval in HTML5 canvas?

Arjun Thakur
Arjun Thakur
Updated on 15-Mar-2026 1K+ Views

Drawing an oval in HTML5 canvas can be achieved by scaling a circle. Since canvas doesn't have a built-in oval method, we use the scale() transformation to stretch a circle into an elliptical shape. How It Works The technique involves three steps: Save the current canvas state with save() Apply scaling transformation to stretch the circle Draw a circle using arc(), which appears as an oval due to scaling Restore the original state with restore() Example HTML5 Canvas Oval ...

Read More

How to apply antialiasing in HTML5 canvas drawImage()?

Ankith Reddy
Ankith Reddy
Updated on 15-Mar-2026 2K+ Views

HTML5 Canvas provides built-in antialiasing through image smoothing properties to improve the quality of scaled images rendered with drawImage(). Setting Image Smoothing Quality The primary way to control antialiasing is through the imageSmoothingQuality property: const canvas = document.getElementById('canvas'); const ctx = canvas.getContext('2d'); // Set antialiasing quality ctx.imageSmoothingQuality = "high"; // "low", "medium", or "high" // Create a small test image const img = new Image(); img.onload = function() { // Draw scaled image with antialiasing ctx.drawImage(img, 0, 0, 200, 150); }; img.src = ...

Read More

Play local (hard-drive) video file with HTML5 video tag?

George John
George John
Updated on 15-Mar-2026 1K+ Views

The HTML5 tag allows you to play local video files from the user's hard drive using JavaScript's File API and URL.createObjectURL() method. This technique works with MP4, WebM, and Ogg video formats. HTML Structure Create a file input and video element: Local Video Player Your browser does not support the video tag. ...

Read More

Play infinitely looping video on-load in HTML5

Arjun Thakur
Arjun Thakur
Updated on 15-Mar-2026 5K+ Views

HTML5 provides built-in support for playing videos that loop infinitely using the loop attribute. This is useful for background videos, animations, or promotional content that should continuously play. Basic Syntax The element supports three main video formats: MP4, WebM, and Ogg. To create an infinitely looping video, combine the autoplay and loop attributes: Your browser does not support the video element. Key Attributes autoplay: Starts the video automatically when the page loads loop: A boolean attribute that restarts ...

Read More

AngularJS and HTML5 date input value - how to get Firefox to show a readable date value in a date input?

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

The elements of type date allow users to enter dates using a text box or date picker. With the ng-model directive, you can bind AngularJS application data to HTML input controls. However, Firefox has limited support for type="date" and converts values to strings, which can cause display issues. Since you want the date to be a real Date object and not a string, we need to create additional variables and link them together using watchers. The Problem Firefox doesn't fully support HTML5 date inputs and may not display dates in a readable format. The browser treats ...

Read More
Showing 121–130 of 328 articles
« Prev 1 11 12 13 14 15 33 Next »
Advertisements