Search completed in 1.31 seconds.
34 results for "clientwidth":
Your results are loading. Please wait...
Element.clientWidth - Web APIs
The Element.clientWidth property is zero for inline elements and elements with no CSS; otherwise, it's the inner width of an element in pixels. It includes padding but excludes borders, margins, and vertical scrollbars (if present). When clientWidth is used on the root element (the <html> element), (or on <body> if the document is in quirks mode), the viewport's width (excluding any scrollbar) is returned. This is a special case of clientWidth. Note: This property will round the value to an integer. If you need a fractional value, use element.getBoundingClientRect(). Syntax var intElemClientWidth = element.clientWidth; intElemClientWidth is an integer corresponding to the clientWidth of element in pixels. The clientWidth property is read-only. Example Specification Specification...
...nteger. If you need a fractional value, use element.getBoundingClientRect(). Syntax var intElemClientWidth = element.clientWidth; intElemClientWidth is an integer corresponding to the clientWidth of element in pixels. The clientWidth property is read-only. Example Specification Specification Status Comment CSS Object Model (CSSOM) View ModuleThe definition of 'clientWidth' in that specification. Working Draft Notes clientWidth was first introduced in the MS IE DHTML object model. ...
Linear-gradient Generator - CSS: Cascading Style Sheets
*******************************************/ // Updates properties of UI elements /*************************************************************************/ ColorPicker.prototype.updateColor = function updateColor(e) { var x = e.pageX - this.picking_area.offsetLeft; var y = e.pageY - this.picking_area.offsetTop; // width and height should be the same var size = this.picking_area.clientWidth; if (x > size) x = size; if (y > size) y = size; if (x < 0) x = 0; if (y < 0) y = 0; var value = 100 - (y * 100 / size) | 0; var saturation = x * 100 / size | 0; if (this.picker_mode === 'HSV') this.color.setHSV(this.color.hue, saturation, value); if (this.picker_mode === 'HSL') this.color.setHSL(this.color.hue, saturation, value); this.color_picker.style.left = x + 'p...
...htness', value); this.notify('saturation', saturation); this.notify('red', this.color.r); this.notify('green', this.color.g); this.notify('blue', this.color.b); this.notify('hexa', this.color.getHexa()); notify(this.topic, this.color); }; ColorPicker.prototype.updateHueSlider = function updateHueSlider(e) { var x = e.pageX - this.hue_area.offsetLeft; var width = this.hue_area.clientWidth; if (x < 0) x = 0; if (x > width) x = width; var hue = ((359 * x) / width) | 0; this.updateSliderPosition(this.hue_picker, x - 1); this.setHue(hue); }; ColorPicker.prototype.updateAlphaSlider = function updateAlphaSlider(e) { var x = e.pageX - this.alpha_mask.offsetLeft; var width = this.alpha_mask.clientWidth; if (x < 0) x = 0; if (x > width) x = width; this.color.a =...
...; this.notify('hexa', this.color.getHexa()); notify(this.topic, this.color); }; /*************************************************************************/ // Update positions of various UI elements /*************************************************************************/ ColorPicker.prototype.updatePickerPosition = function updatePickerPosition() { var size = this.picking_area.clientWidth; var value = 0; if (this.picker_mode === 'HSV') value = this.color.value; if (this.picker_mode === 'HSL') value = this.color.lightness; var x = (this.color.saturation * size / 100) | 0; var y = size - (value * size / 100) | 0; this.color_picker.style.left = x + 'px'; this.color_picker.style.top = y + 'px'; }; ColorPicker.prototype.updateSliderPosition = function updateSl...
...And 6 more matches
Box-shadow generator - CSS: Cascading Style Sheets
topic) { var slider = sliders[topic]; if (slider === null || slider === undefined) return; if (slider.value - slider.step >= slider.min) { slider.value -= slider.step; setValue(topic, slider.value) notify.call(slider); } } // this = Slider object var updateSlider = function updateSlider(e) { var node = this.node; var pos = e.pageX - node.offsetLeft; var width = node.clientWidth; var delta = this.max - this.min; var offset = this.pointer.clientWidth + 4; // border width * 2 if (pos < 0) pos = 0; if (pos > width) pos = width; var value = pos * delta / width | 0; var precision = value % this.step; value = value - precision + this.min; if (precision > this.step / 2) value = value + this.step; if (this.snap) pos = (value - this.min) * width / delt...
...snap) pos = (value - this.min) * width / delta; this.pointer.style.left = pos - offset/2 + "px"; this.value = value; node.setAttribute('data-value', value); notify.call(this); } var setValue = function setValue(topic, value) { var slider = sliders[topic]; if (value > slider.max || value < slider.min) return; var delta = slider.max - slider.min; var width = slider.node.clientWidth; var offset = slider.pointer.clientWidth; var pos = (value - slider.min) * width / delta; slider.value = value; slider.pointer.style.left = pos - offset / 2 + "px"; slider.node.setAttribute('data-value', value); notify.call(slider); } var setMouseTracking = function setMouseTracking(elem, callback) { elem.addEventListener("mousedown", function(e) { callback(e); document.ad...
...picker; var hue_selector; var alpha_selector; var pick_object; var info_rgb; var info_hsv; var info_hexa; var output_color; var color = new Color(); var subscribers = []; var updateColor = function updateColor(e) { var x = e.pageX - gradient_area.offsetLeft; var y = e.pageY - gradient_area.offsetTop; // width and height should be the same var size = gradient_area.clientWidth; if (x > size) x = size; if (y > size) y = size; if (x < 0) x = 0; if (y < 0) y = 0; var value = 100 - (y * 100 / size) | 0; var saturation = x * 100 / size | 0; color.setHSV(color.hue, saturation, value); // should update just // color pointer location updateUI(); notify("color", color); } var updateHue = function updateHue(e) { var x = e.page...
...And 5 more matches
Color picker tool - CSS: Cascading Style Sheets
******************/ // Updates properties of UI elements /*************************************************************************/ ColorPicker.prototype.updateColor = function updateColor(e) { var x = e.pageX - this.picking_area.offsetLeft; var y = e.pageY - this.picking_area.offsetTop; var picker_offset = 5; // width and height should be the same var size = this.picking_area.clientWidth; if (x > size) x = size; if (y > size) y = size; if (x < 0) x = 0; if (y < 0) y = 0; var value = 100 - (y * 100 / size) | 0; var saturation = x * 100 / size | 0; if (this.picker_mode === 'HSV') this.color.setHSV(this.color.hue, saturation, value); if (this.picker_mode === 'HSL') this.color.setHSL(this.color.hue, saturation, value); this.color_picker.style.left = x - pi...
...htness', value); this.notify('saturation', saturation); this.notify('red', this.color.r); this.notify('green', this.color.g); this.notify('blue', this.color.b); this.notify('hexa', this.color.getHexa()); notify(this.topic, this.color); }; ColorPicker.prototype.updateHueSlider = function updateHueSlider(e) { var x = e.pageX - this.hue_area.offsetLeft; var width = this.hue_area.clientWidth; if (x < 0) x = 0; if (x > width) x = width; // TODO 360 => 359 var hue = ((359 * x) / width) | 0; // if (hue === 360) hue = 359; this.updateSliderPosition(this.hue_picker, x); this.setHue(hue); }; ColorPicker.prototype.updateAlphaSlider = function updateAlphaSlider(e) { var x = e.pageX - this.alpha_area.offsetLeft; var width = this.alpha_area.clientWidth; if (x < 0) x ...
...; this.notify('hexa', this.color.getHexa()); notify(this.topic, this.color); }; /*************************************************************************/ // Update positions of various UI elements /*************************************************************************/ ColorPicker.prototype.updatePickerPosition = function updatePickerPosition() { var size = this.picking_area.clientWidth; var value = 0; var offset = 5; if (this.picker_mode === 'HSV') value = this.color.value; if (this.picker_mode === 'HSL') value = this.color.lightness; var x = (this.color.saturation * size / 100) | 0; var y = size - (value * size / 100) | 0; this.color_picker.style.left = x - offset + 'px'; this.color_picker.style.top = y - offset + 'px'; }; ColorPicker.prototype.upda...
...And 3 more matches
Border-radius generator - CSS: Cascading Style Sheets
er.prototype.setRadius = function setRadius(value) { this.radius.style.display = 'block'; this.size = 2 * value; this.node.style.width = this.size + units[this.unitR]; this.node.style.height = this.size + units[this.unitR]; this.updateBorderRadius(); } RadiusContainer.prototype.setUnitX = function setUnitX(value) { this.unitX = value; if (this.unitX === 0) this.maxW = 2 * subject.clientWidth; if (this.unitX === 1) this.maxW = 200; InputSliderManager.setUnit(this.topic + '-w', units[this.unitX]); InputSliderManager.setMax(this.topic + '-w', this.maxW / 2); } RadiusContainer.prototype.setUnitY = function setUnitY(value) { this.unitY = value; if (this.unitY === 0) this.maxH = 2 * subject.clientHeight; if (this.unitY === 1) this.maxH = 200; InputSliderManager.setUnit(thi...
...s.unitY === 0) this.maxH = 2 * subject.clientHeight; if (this.unitY === 1) this.maxH = 200; InputSliderManager.setUnit(this.topic + '-h', units[this.unitY]); InputSliderManager.setMax(this.topic + '-h', this.maxH / 2); } RadiusContainer.prototype.setUnitR = function setUnitR(value) { this.unitR = value; if (this.unitR === 0) this.maxR = 2 * Math.min(subject.clientHeight , subject.clientWidth); if (this.unitR === 1) this.maxR = 200; InputSliderManager.setUnit(this.topic, units[this.unitR]); InputSliderManager.setMax(this.topic, this.maxR / 2); } RadiusContainer.prototype.updateUnits = function updateUnits(unit) { if (this.rounded) { this.setUnitR(this.unitR); return; } if (unit === 0) this.setUnitX(this.unitX); if (unit === 1) this.setUnitY(this.uni...
... this.updateHeight(); } if (deltaX || deltaY) this.updateBorderRadius(); } /** * Tool Manager */ var Tool = (function Tool() { var preview; var preview_ui; var radius_containers = []; var border_width = 3; var borders1 = [null, null, null, null]; var borders2 = [0, 0, 0, 0]; var updateUIWidth = function updateUIWidth(value) { var pwidth = subject.parentElement.clientWidth; var left = (pwidth - value) / 2; subject.style.width = value + "px"; for (var i = 0; i < 4; i++) radius_containers[i].updateUnits(0); } var updateUIHeight = function updateUIHeight(value) { var pheight = subject.parentElement.clientHeight; var top = (pheight - value) / 2; subject.style.height = value + "px"; subject.style.top = top - border_width + "px"; for (v...
...And 2 more matches
Things I've tried to do with XUL - Archive of obsolete content
current Gecko will quite happily split the space out according to flex, ignoring the contents of each box, as desired. From my reading of the code, just height="0" should work, but it doesn't seem to. This trick doesn't work in 1.4, but works in 1.7 and current versions. Obtaining the rect of an element You can't obtain the actual visible rect of an element. HTML elements have the non-standard clientWidth/clientHeight properties (see http://www.mozilla.org/docs/dom/domr...entHeight.html); no equivalent exists for XUL. Enn: most people would use the box object width and height properties, or do you want something else? Vlad: the boxObject width/height are the actual width and height of the box, regardless of the actual visible portion of the box (clipped by the window borders, for example). This is...
...exists for XUL. Enn: most people would use the box object width and height properties, or do you want something else? Vlad: the boxObject width/height are the actual width and height of the box, regardless of the actual visible portion of the box (clipped by the window borders, for example). This is assuming no scrolling is going on. Resize event problems Going with the inability to obtain the clientWidth/clientHeight of XUL elements, it's impossible to handle the "resize" event yourself to grow/shrink content as needed -- as you grow the content, when you shrink the window, the content will simply be clipped (because now it has a bigger size than the window). You have no way of finding out what the clipped size is, so you can never shrink the content. An ugly workaround for this problem might inc...
...esize" event yourself to grow/shrink content as needed -- as you grow the content, when you shrink the window, the content will simply be clipped (because now it has a bigger size than the window). You have no way of finding out what the clipped size is, so you can never shrink the content. ...
... XBL in listboxes Using XBL bindings in listboxes is not easy because there is a big bug there: if you create from JS an element you want to bind, and if it is hidden when the listbox is first rendered, the listbox does not create a frame for it, and the xbl doesn't get attached... ...
Browser Detection and Cross Browser Support - Archive of obsolete content
e 7.01 Netscape 7.01 Examples If you are like me, you learn best from examples. Studying how other authors use browser detection and cross browser coding techniques is the best way to learn. Example 1 - object based feature detection This example illustrates the use of feature detection. ...
...uthors use browser detection and cross browser coding techniques is the best way to learn. Example 1 - object based feature detection This example illustrates the use of feature detection. Note that Gecko 1.0 (Netscape 7) and later implement the proprietary Internet Explorer feature clientWidth while Netscape 6 did not. In this example, Netscape 7 and Internet Explorer 5+ will automatically use clientWidth while Netscape Navigator 4, Netscape 6, CompuServe 7 and Opera will use innerWidth. ...
...ietary Internet Explorer feature clientWidth while Netscape 6 did not. In this example, Netscape 7 and Internet Explorer 5+ will automatically use clientWidth while Netscape Navigator 4, Netscape 6, CompuServe 7 and Opera will use innerWidth. Compare how you would have had to code this using vendor/version based detection approaches. ...
...lorer 5+ will automatically use clientWidth while Netscape Navigator 4, Netscape 6, CompuServe 7 and Opera will use innerWidth. Compare how you would have had to code this using vendor/version based detection approaches. if (windowRef.document.body && typeof(windowRef.document.body.clientWidth) == 'number') { // Gecko 1.0 (Netscape 7) and Internet Explorer 5+ width = windowRef.document.body.clientWidth; } else if (typeof(windowRef.innerWidth) == 'number') { // Navigator 4.x, Netscape 6.x, CompuServe 7 and Opera width = windowRef.innerWidth; } Example 2 - object based feature detection Cross Browser Support This example also illustrates the use of feature detection and shows the complications that can arise from the non standard implementations in other browsers. function moveElement(id...
Viewport concepts - CSS: Cascading Style Sheets
smaller, and the document is the website, which can be much taller or wider than the viewport. To recap, the viewport is basically the part of the document that is currently visible. Viewport sizes are mutable The width of the viewport is not always the width of the window. ...
...This is the viewport width. The Window.innerWidth is the width, in CSS pixels, of the browser window viewport including, if rendered, the vertical scrollbar. ...
...rome: measurements were taken on a browser with an address bar and bookmarks bar totalling 100px in height, but no chrome on the left or right of the window. The area within the innerHeight and innerWidth is generally considered the layout viewport. The browser chrome is not considered part of the viewport. When zoomed in, both Firefox and Chrome report the new CSS pixel size for innerWidth and clientWidth. ...
...rt. The browser chrome is not considered part of the viewport. When zoomed in, both Firefox and Chrome report the new CSS pixel size for innerWidth and clientWidth. The values returned for the outerWidth and outerHeight depend on the browser: Firefox reports the new value in CSS pixels, but Chrome returns the length in the default pixel size. When zoomed in you may get: document.documentElement.clientWidth /* 800 */ window.innerWidth /* 800 */ window.outerWidth /* 800 in Firefox, 1200 in chrome */ document.documentElement.clientHeight /* 533 */ window.innerHeight /* 533 */ window.outerHeight /* 596 in Firefox, 900 in chrome */ The viewport was originally 1200 x 800 pixels. Upon zooming in, the viewport became 800 x 533 pixels. This is the layout viewport. Sticky headers or footers, with the fol...
Document.width - Web APIs
Web › API › Document › width
Note: Starting in Gecko 6.0, document.width is no longer supported. Instead, use document.body.clientWidth. See element.clientWidth. Returns the width of the <body> element of the current document in pixels. Not supported by Internet Explorer. ...
... in Gecko 6.0, document.width is no longer supported. Instead, use document.body.clientWidth. See element.clientWidth. Returns the width of the <body> element of the current document in pixels. Not supported by Internet Explorer. ...
...ent.body.clientWidth. See element.clientWidth. Returns the width of the <body> element of the current document in pixels. Not supported by Internet Explorer. ...
Property - Archive of obsolete content
<< XUL Reference accessible accessibleType accessKey align allNotifications allowEvents alwaysOpenPopup amIndicator appLocale autoCheck autoFill autoFillAfterMatch boxObject browsers builder builderView buttons canAdvance canGoBack canGoForward canRewind checked checkState child children className clickSelectsAll clientHeight clientWidth collapsed color columns command commandManager completeDefaultIndex container contentDocument contentPrincipal contentTitle contentView contentViewerEdit contentViewerFile contentWindow contextMenu control controller controllers crop current currentIndex currentItem currentNotification currentPage currentPane currentSet currentURI customToolbar...
... userAction value valueNumber view webBrowsereFind webNavigation webProgress width wizardPages wrapAround year yearLeadingZero Related DOM element properties DOM:element.attributes DOM:element.baseURI DOM:element.childElementCount DOM:element.childNodes DOM:element.children DOM:element.clientHeight DOM:element.clientLeft DOM:element.clientTop DOM:element.clientWidth DOM:element.cloneNode DOM:element.firstChild DOM:element.firstElementChild DOM:element.lastChild DOM:element.lastElementChild DOM:element.localName DOM:element.namespaceURI DOM:element.nextElementSibling DOM:element.nextSibling DOM:element.nodeName DOM:element.nodeType DOM:element.nodeValue DOM:element.ownerDocument DOM:element.parentNode DOM:element.prefix DOM:ele...
Video and Audio APIs - Learn web development
Then we initialize two more variables -- minuteValue and secondValue. The two if statements work out whether the number of minutes and se...
...add a leading zero to the values, in the same way that a digital clock display works. The actual time value to display is set as minuteValue plus a colon character plus secondValue. The Node.textContent value of the timer is set to the time value, so it displays in the UI. The length we should set the inner <div> to is worked out by first working out the width of the outer <div> (any element's clientWidth property will contain its length), and then multiplying it by the HTMLMediaElement.currentTime divided by the total HTMLMediaElement.duration of the media. We set the width of the inner <div> to equal the calculated bar length, plus "px", so it will be set to that number of pixels. Fixing play and pause There is one problem left to fix. If the play/pause or stop buttons are pressed while the ...
Element - Web APIs
Web › API › Element
ibutes. Element.className Is a DOMString representing the class of the element. Element.clientHeight Read only Returns a Number representing the inner height of the element. Element.clientLeft Read only Returns a Number representing the width of the left border of the element. Element.clientTop Read only Returns a Number representing the width of the top border of the element. Element.clientWidth Read only Returns a Number representing the inner width of the element. Element.computedName Read only Returns a DOMString containing the label exposed to accessibility. Element.computedRole Read only Returns a DOMString containing the ARIA role that has been applied to a particular element. Element.id Is a DOMString representing the id of the element. Element.innerHTML Is a DOMString...
...definition of 'Element' in that specification. Working Draft Added the following properties: innerHTML, and outerHTML. Added the following method: insertAdjacentHTML(). CSS Object Model (CSSOM) View ModuleThe definition of 'Element' in that specification. Working Draft Added the following properties: scrollTop, scrollLeft, scrollWidth, scrollHeight, clientTop, clientLeft, clientWidth, and clientHeight. Added the following methods: getClientRects(), getBoundingClientRect(), scroll(), scrollBy(), scrollTo() and scrollIntoView(). Element Traversal SpecificationThe definition of 'Element' in that specification. Obsolete Added inheritance of the ElementTraversal interface. DOMThe definition of 'Element' in that specification. Living Standard Added...
WebGLRenderingContext - Web APIs
ties and variables you can tweak are different for each API. Effect of canvas size on rendering with WebGL With scissor() and clear() we can demonstrate how the WebGL drawing buffer is affected by the size of the canvas. The size of the first canvas is set to the styled Element size, determined by CSS. This is done by assigning the width and height properties of the canvas to the values of the clientWidth and clientHeight properties, respectively. In contrast, no such assignment is done for the second canvas. The internal width and height properties of the canvas remain at default values, which are different than the actual size of the canvas Element in the browser window. The effect is clearly visible when using scissor() and clear() to draw a square in the center of the canvas, by specifying i...
..." + "Your browser or device may not support WebGL."; return; } gl.viewport(0, 0, ...
Canvas size and WebGL - Web APIs
ize in CSS pixels, as it appears in the browser window. Effect of canvas size on rendering with WebGL With scissor() and clear() we can demonstrate how the WebGL drawing buffer is affected by the size of the canvas. The size of the first canvas is set to the styled Element size, determined by CSS. This is done by assigning the width and height properties of the canvas to the values of the clientWidth and clientHeight properties, respectively. In contrast, no such assignment is done for the second canvas. The internal width and height properties of the canvas remain at default values, which are different than the actual size of the canvas Element in the browser window. The effect is clearly visible when using scissor() and clear() to draw a square in the center of the canvas, by specifying i...
..." + "Your browser or device may not support WebGL."; return; } gl.viewport(0, 0, ...
jspage - Archive of obsolete content
bottom=k.top+k.height;return k;},computePosition:function(h){return{left:h.x-e(this,"margin-left"),top:h.y-e(this,"margin-top")}; },setPosition:function(h){return this.setStyles(this.computePosition(h));}});Native.implement([Document,Window],{getSize:function(){if(Browser.Engine.presto||Browser.Engine.webkit){var i=this.getWindow(); return{x:i.innerWidth,y:i.innerHeight};}var h=a(this);return{x:h.clientWidth,y:h.clientHeight};},getScroll:function(){var i=this.getWindow(),h=a(this); return{x:i.pageXOffset||h.scrollLeft,y:i.pageYOffset||h.scrollTop};},getScrollSize:function(){var i=a(this),h=this.getSize();return{x:Math.max(i.scrollWidth,h.x),y:Math.max(i.scrollHeight,h.y)}; },getPosition:function(){return{x:0,y:0};},getCoordinates:function(){var h=this.getSize();return{top:0,left:0,bottom:h.y,right:h.
Responsive images - Learn web development
hat had many pictures on it. Using this technique could save mobile users a lot of bandwidth. Note: When testing this with a desktop browser, if the browser fails to load the narrower images when you've got its window set to the narrowest width, have a look at what the viewport is (you can approximate it by going into the browser's JavaScript console and typing in document.querySelector('html').clientWidth). Different browsers have minimum sizes that they'll let you reduce the window width to, and they might be wider than you'd think. When testing it with a mobile browser, you can use tools like Firefox's about:debugging page to inspect the page loaded on the mobile using the desktop developer tools. To see which images were loaded, you can use Firefox DevTools's Network Monitor tab. Older bro...
Looping code - Learn web development
{ margin: 0; } button { position: absolute; top: 5px; left: 5px; } </style> </head> <body> <button>Update</button> <canvas></canvas> <script> const btn = document.querySelector('button'); const canvas = document.querySelector('canvas'); const ctx = canvas.getContext('2d'); let WIDTH = document.documentElement.clientWidth; let HEIGHT = document.documentElement.clientHeight; canvas.width = WIDTH; canvas.height = HEIGHT; function random(number) { return Math.floor(Math.random()*number); } function draw() { ctx.clearRect(0,0,WIDTH,HEIGHT); for (let i = 0; i < 100; i++) { ctx.beginPath(); ctx.fillStyle = 'rgba(255,0,0,0.5)'; ctx.arc(random(WIDTH), ra...
Performance best practices for Firefox front-end engineers
ke it easier for priviledged code to queue up JavaScript to run when we know that the DOM is not dirty, and size, position, and style information is cheap to query for. Here's an example: async function matchWidth(elem, otherElem) { let width = await window.promiseDocumentFlushed(() => { // Do _not_ under any circumstances write to the DOM in one of these // callbacks! return elem.clientWidth; }); requestAnimationFrame(() => { otherElem.style.width = `${width}px`; }); } Please see the section on promiseDocumentFlushed in Detecting and avoiding synchronous style flushes for more information on how to use the API. Note that queries for size and position information are only expensive if the DOM has been written to. Otherwise, we're doing a cheap look-up of cached informatio...
Determining the dimensions of elements - Web APIs
and height. As an example, if the element has width: 100px; and transform: scale(0.5); the getBoundingClientRect() will return 50 as the width, while offsetWidth will return 100. What's the size of the displayed content? If you need to know how much space the actual displayed content takes up, including padding but not including the border, margins, or scrollbars, you want to use the Element.clientWidth and Element.clientHeight properties: How big is the content? If you need to know the actual size of the content, regardless of how much of it is currently visible, you need to use the Element.scrollWidth and Element.scrollHeight properties. These return the width and height of the entire content of an element, even if only part of it is presently visible due to the use of scroll bars. For ex...
Detecting device orientation - Web APIs
lid #CCC; border-radius: 10px; } .ball { position: absolute; top : 90px; left : 90px; width : 20px; height: 20px; background: green; border-radius: 100%; } Now, if we move our device, the ball will move accordingly: var ball = document.querySelector('.ball'); var garden = document.querySelector('.garden'); var output = document.querySelector('.output'); var maxX = garden.clientWidth - ball.clientWidth; var maxY = garden.clientHeight - ball.clientHeight; function handleOrientation(event) { var x = event.beta; // In degree in the range [-180,180] var y = event.gamma; // In degree in the range [-90,90] output.innerHTML = "beta : " + x + "\n"; output.innerHTML += "gamma: " + y + "\n"; // Because we don't want to have the device upside down // We constrain the x...
Element.scrollWidth - Web APIs
The Element.scrollWidth read-only property is a measurement of the width of an element's content, including content not visible on the screen due to overflow. The scrollWidth value is equal to the minimum width the element would require in order to fit all the content in the viewport without using a horizontal scrollbar. The width is measured in the same way as clientWidth: it includes the element's padding, but not its border, margin or vertical scrollbar (if present). It can also include the width of pseudo-elements such as ::before or ::after. If the element's content can fit without a need for horizontal scrollbar, its scrollWidth is equal to clientWidth This property will round the value to an integer. If you need a fractional value, use element.getBoundingClientRect(). Syntax var xScroll...
Index - Web APIs
Web › API › Index
there is an overflow causing a left vertical scrollbar to be rendered. clientLeft does not include the left margin or the left padding. clientLeft is read-only. 1105 Element.clientTop API, CSSOM View, NeedsAgnostify, NeedsMarkupWork, Property, Reference The width of the top border of an element in pixels. It is a read-only, integer property of element. 1106 Element.clientWidth API, CSSOM View, NeedsMarkupWork, Property, Reference The Element.clientWidth property is zero for inline elements and elements with no CSS; otherwise, it's the inner width of an element in pixels. It includes padding but excludes borders, margins, and vertical scrollbars (if present). 1107 Element.closest() API, DOM, Element, Method, Reference For browsers that do ...
Multi-touch interaction - Web APIs
It also calls preventDefault() to keep the browser from applying further event handling (for example, mou...
VisualViewport - Web APIs
can get a window's visual viewport using Window.visualViewport. Note: Only the top-level window has a visual viewport that's distinct from the layout viewport. Therefore, it's generally only the VisualViewport object of the top-level window that's useful. For an <iframe>, visual viewport metrics like VisualViewport.width always correspond to layout viewport metrics like document.documentElement.clientWidth. Properties VisualViewport also inherits properties from its parent, EventTarget. VisualViewport.offsetLeft Read only Returns the offset of the left edge of the visual viewport from the left edge of the layout viewport in CSS pixels. VisualViewport.offsetTop Read only Returns the offset of the top edge of the visual viewport from the top edge of the layout viewport in CSS pixels. Visu...
Basic scissoring - Web APIs
("load", function setupWebGL (evt) { "use strict" window.removeEventListener(evt.type, setupWebGL, false); var paragraph = document.querySelector("p"); var canvas = document.querySelector("canvas"); // The following two lines set the size (in CSS pixels) of // the drawing buffer to be identical to the size of the // canvas HTML element, as determined by CSS. canvas.width = canvas.clientWidth; canvas.height = canvas.clientHeight; var gl = canvas.getContext("webgl") || canvas.getContext("experimental-webgl"); if (!gl) { paragraph.innerHTML = "Failed to get WebGL context. " + "Your browser or device may not support WebGL."; return; } gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight); // Enable scissoring operation and define the positio...
Boilerplate 1 - Web APIs
</canvas> CSS body { text-align : center; } canvas { display : block; width : 280px; height : 210px; margin : auto; padding : 0; border : none; background-color : black; } button { display : block; font-size : inherit; margin : auto; padding : 0.6em; } JavaScript function getRenderingContext() { var canvas = document.querySelector("canvas"); canvas.width = canvas.clientWidth; canvas.height = canvas.clientHeight; var gl = canvas.getContext("webgl") || canvas.getContext("experimental-webgl"); if (!gl) { var paragraph = document.querySelector("p"); paragraph.innerHTML = "Failed to get WebGL context." + "Your browser or device may not support WebGL."; return null; } gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight); gl...
Hello GLSL - Web APIs
{ gl.enableVertexAttribArray(0); buffer = gl.createBuffer(); gl.bindBuffer(gl.ARRAY_BUFFER, buffer); gl.vertexAttribPointer(0, 1, gl.FLOAT, false, 0, 0); } function cleanup() { gl.useProgram(null); if (buffer) gl.deleteBuffer(buffer); if (program) gl.deleteProgram(program); } function getRenderingContext() { var canvas = document.querySelector("canvas"); canvas.width = canvas.clientWidth; canvas.height = canvas.clientHeight; var gl = canvas.getContext("webgl") || canvas.getContext("experimental-webgl"); if (!gl) { var paragraph = document.querySelector("p"); paragraph.innerHTML = "Failed to get WebGL context." + "Your browser or device may not support WebGL."; return null; } gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight); gl...
Hello vertex attributes - Web APIs
new Float32Array([0.0]), gl.STATIC_DRAW); gl.vertexAttribPointer(0, 1, gl.FLOAT, false, 0, 0); } window.addEventListener("beforeunload", cleanup, true); function cleanup() { gl.useProgram(null); if (buffer) gl.deleteBuffer(buffer); if (program) gl.deleteProgram(program); } function getRenderingContext() { var canvas = document.querySelector("canvas"); canvas.width = canvas.clientWidth; canvas.height = canvas.clientHeight; var gl = canvas.getContext("webgl") || canvas.getContext("experimental-webgl"); if (!gl) { var paragraph = document.querySelector("p"); paragraph.innerHTML = "Failed to get WebGL context." + "Your browser or device may not support WebGL."; return null; } gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight); gl...
Raining rectangles - Web APIs
th - rect.size[0]), gl.drawingBufferHeight ]; rect.velocity = 1.0 + 6.0*Math.random(); rect.color = getRandomVector(); gl.clearColor(rect.color[0], rect.color[1], rect.color[2], 1.0); function getRandomVector() { return [Math.random(), Math.random(), Math.random()]; } } function getRenderingContext() { var canvas = document.querySelector("canvas"); canvas.width = canvas.clientWidth; canvas.height = canvas.clientHeight; var gl = canvas.getContext("webgl") || canvas.getContext("experimental-webgl"); if (!gl) { var paragraph = document.querySelector("p"); paragraph.innerHTML = "Failed to get WebGL context." + "Your browser or device may not support WebGL."; return null; } gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight); gl...
Scissor animation - Web APIs
gl.drawingBufferHeight ]; // Random velocity between 1.0 and 7.0 velocity = 1.0 + 6.0*Math.random(); color = getRandomColor(); gl.clearColor(color[0], color[1], color[2], 1.0); } } function getRandomColor() { return [Math.random(), Math.random(), Math.random()]; } function getRenderingContext() { var canvas = document.querySelector("canvas"); canvas.width = canvas.clientWidth; canvas.height = canvas.clientHeight; var gl = canvas.getContext("webgl") || canvas.getContext("experimental-webgl"); if (!gl) { var paragraph = document.querySelector("p"); paragraph.innerHTML = "Failed to get WebGL context." + "Your browser or device may not support WebGL."; return null; } gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight); gl...
Textures from code - Web APIs
r(gl.ARRAY_BUFFER, buffer); gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([0.0, 0.0]), gl.STATIC_DRAW); gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0); } function cleanup() { gl.useProgram(null); if (buffer) gl.deleteBuffer(buffer); if (program) gl.deleteProgram(program); } function getRenderingContext() { var canvas = document.querySelector("canvas"); canvas.width = canvas.clientWidth; canvas.height = canvas.clientHeight; var gl = canvas.getContext("webgl") || canvas.getContext("experimental-webgl"); if (!gl) { var paragraph = document.querySelector("p"); paragraph.innerHTML = "Failed to get WebGL context." + "Your browser or device may not support WebGL."; return null; } gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight); gl...
Adding 2D content to a WebGL context - Web APIs
ective matrix, a special matrix that is // used to simulate the distortion of perspective in a camera. // Our field of view is 45 degrees, with a width/height // ratio that matches the display size of the canvas // and we only want to see objects between 0.1 units // and 100 units away from the camera. const fieldOfView = 45 * Math.PI / 180; // in radians const aspect = gl.canvas.clientWidth / gl.canvas.clientHeight; const zNear = 0.1; const zFar = 100.0; const projectionMatrix = mat4.create(); // note: glmatrix.js always has the first argument // as the destination to receive the result. mat4.perspective(projectionMatrix, fieldOfView, aspect, zNear, zFar); // Set the drawing position to the "...
Window.innerWidth - Web APIs
Web › API › Window › innerWidth
ndow.innerWidth; Value An integer value indicating the width of the window's layout viewport in pixels. This property is read-only, and has no default value. To change the window's width, use one of the Window methods for resizing windows, such as resizeBy() or resizeTo(). Usage notes If you need to obtain the width of the window minus the scrollbar and borders, use the root <html> element's clientWidth property instead. The innerWidth property is available on any window or object that behaves like a window, such as a frame or tab. Example // This will return the width of the viewport var intFrameWidth = window.innerWidth; // This will return the width of the frame viewport within a frameset var intFrameWidth = self.innerWidth; // This will return the width of the viewport of the closest fr...
Border-image generator - CSS: Cascading Style Sheets
{ elem.style.left = e.clientX - offsetLeft + 'px'; elem.style.top = e.clientY - offsetTop + 'px'; }; elem.addEventListener('mousedown', dragStart, false); }; var PreviewControl = function PreviewControl() { var dragging = false; var valueX = null; var valueY = null; var dragStart = function dragStart(e) { if (e.button !== 0) return; valueX = e.clientX - preview.clientWidth; valueY = e.clientY - preview.clientHeight; dragging = true; document.addEventListener('mousemove', mouseDrag); }; var dragEnd = function dragEnd(e) { if (e.button !== 0 || dragging === false) return; document.removeEventListener('mousemove', mouseDrag); dragging = false; }; var mouseDrag = function mouseDrag(e) { InputSliderManager.setValue('preview-width', e...