Home Web Front-end JS Tutorial js function code to get the size of the scroll bar_javascript skills

js function code to get the size of the scroll bar_javascript skills

May 16, 2016 pm 05:58 PM
size scroll bar

This is relatively simple, just a record.

Create a nested node, let the outer node generate a scroll bar, and then use offsetWidth - clientWidth to get the scroll bar width. It should be noted that in order to avoid page shaking, you can set the outer element position:absolute and visibility:hidden

Reference:

Copy code The code is as follows:

function getScrollWith(){
var wrap = setAttributes(document.createElement('div'),{
style : {
width : '200px',
height: '200px',
overflow: 'auto',
position:'absolute',
visibility:'hidden'
}
})
var inner = setAttributes(document.createElement('div'),{
style : {
width : '100px',
height: '2000px'
}
})
document.body.appendChild(wrap);
wrap.appendChild(inner);
var w = wrap.offsetWidth - wrap.clientWidth;
document.body.removeChild(wrap);
wrap = null;
inner = null;
return w;
}
function setAttributes(elem,opts){
for(var key in opts){
if(typeof opts [key] == 'string'){
elem[key] = opts[key];
}else{
if(!elem[key]){
elem[key] = { };
}
setAttributes(elem[key],opts[key]);
}
}
return elem;
}
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Microsoft brings Windows 11's Fluent scrollbars to Google Chrome Microsoft brings Windows 11's Fluent scrollbars to Google Chrome Apr 14, 2023 am 10:52 AM

Unlike Windows 10, Windows 11 features new modern “fluid scrollbars” that change shape when users interact with them. Fluent scrollbars are dynamic in nature, they automatically scale in different form factors or when you change the window size, and it is currently used in apps like Settings, Media Players, and more. Google Chrome may soon have smooth scrollbar functionality, according to a new proposal from Microsoft. Microsoft says in a proposal that they want to modernize old scroll bars in Chrome

What is the size of a4 paper in centimeters? What is the size of a4 paper in centimeters? Feb 11, 2024 pm 11:51 PM

A4 paper is now used in many places, such as office, study, etc. The paper used for copying is basically A4 paper. Many friends don’t know how many centimeters the size of A4 paper is. Let’s take a look. Bar. 1. Size A4 paper is 21cm × 29.7cm (210mm × 297mm). The paper size used in most countries in the world adopts this international standard. 2. Origin A4 paper is 210mm×297mm. Reason 1: A rectangle with a length of 2 and a width of The resulting ratio is . However, 297 divided by 210, the result is 1.414, which is close to, and this ratio is exactly a piece of paper

How to hide scroll bar scrolling in react How to hide scroll bar scrolling in react Dec 21, 2022 pm 03:38 PM

How to hide scroll bar scrolling in react: 1. Open the corresponding "react-native" file; 2. Set horizontal scrolling through horizontal; 3. Hide the horizontal scroll bar by setting the value of "showsHorizontalScrollIndicator" to "false".

How to calculate computer size How to calculate computer size Mar 20, 2023 pm 01:43 PM

How to calculate computer size: 1. Find a flat and stable table, place the monitor on the table, and keep the monitor stable; 2. Use a ruler to measure the diagonal length; 3. Convert the units between centimeters and feet. , just calculate the monitor size.

What is the size of a4 paper? What is the size of a4 paper? Apr 25, 2024 am 11:55 AM

1. The aspect ratio of A4 paper is different from the common 2:3 or 3:4. Its unique ratio of √2:1 makes it stand out among many paper sizes. 2. This special ratio provides ideal visual effects and practicality for A4 paper.

How to set the scroll bar to always show on Mac system - How to set the scroll bar to always show How to set the scroll bar to always show on Mac system - How to set the scroll bar to always show Mar 18, 2024 pm 06:22 PM

Recently, some friends have consulted the editor about how to set the scroll bar of the Mac system to always display. The following will bring you the method of setting the scroll bar of the Mac system to always display. Friends who need it can learn more. Step 1: In the system start menu, select the [System Preferences] option. Step 3: On the System Preferences page, select the [General] option. Step 3: On the general page, select [Always] to display scroll bars.

How to reduce the size of photos 'A must-see for beginners: Detailed steps to compress image size' How to reduce the size of photos 'A must-see for beginners: Detailed steps to compress image size' Feb 06, 2024 pm 06:55 PM

Many friends use cameras to record their living habits. Some professional photography friends may also use SLR cameras to take clearer photos. However, although the photos taken by SLR cameras are clear, for a photo of tens of megabytes, it will undoubtedly increase the pressure on the storage device. So, is there any way to reduce the size of the photo while retaining the details of the picture as much as possible? In fact, just compress the image. So how to compress the image size? Here are two good methods to share. Method 1: We can import the image in the beauty tool without any other processing and editing. When saving a picture, the system will provide image quality adjustment options, and we can drag the slider to adjust the retained sharpness. When the estimated size meets your needs, click Save. Method 2: ①. First open this "

What is the size of a5 What is the size of a5 Apr 24, 2024 pm 05:53 PM

1. A5 paper is an international standard paper size, its size is 148 mm x 210 mm (5.83 inches x 8.27 inches). 2. It is often used in various applications such as letterheads, notebooks, leaflets, and books. 3. The size of A5 paper is slightly larger than half of A4 paper, and it is the fifth size in the A series of paper sizes. 4. This series of sizes was developed by German engineer Walter Portmann in the early 20th century to create a series of standard paper sizes based on the golden ratio.

See all articles