HTML Articles

Page 130 of 151

How to set all the background properties in one declaration with JavaScript DOM?

Swarali Sree
Swarali Sree
Updated on 15-Mar-2026 169 Views

To set multiple background properties in JavaScript, use the background property. This shorthand property allows you to set background color, image, position, repeat, and other background-related properties in a single declaration. Syntax element.style.background = "color image repeat attachment position"; Background Property Values The background shorthand can include the following properties in any order: background-color: Sets the background color background-image: Sets the background image using url() background-repeat: Controls image repetition (repeat, no-repeat, repeat-x, repeat-y) background-position: Sets image position (left, right, center, top, bottom, or pixel values) background-attachment: Controls scrolling behavior (scroll, fixed) ...

Read More

How to search the querystring part of the href attribute of an area in JavaScript?

Ramu Prasad
Ramu Prasad
Updated on 15-Mar-2026 194 Views

To get the querystring from the href attribute of an area element, use the search property. This property returns the query portion of the URL, including the question mark. Syntax areaElement.search Return Value Returns a string containing the query portion of the href URL, including the leading question mark (?). Returns an empty string if no query parameters exist. Example ...

Read More

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

Rishi Raj
Rishi Raj
Updated on 15-Mar-2026 708 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 563 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 668 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 711 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 728 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
Showing 1291–1300 of 1,509 articles
« Prev 1 128 129 130 131 132 151 Next »
Advertisements