Overflow Property Returning Auto Value

overflow property returning auto value

If you are just wanting to remove the inner-vertical scrollbar, you would use the following instead:

html, body {
overflow-x: hidden;
}
body {
overflow-y: hidden;
}

Hide the horizontal scrollbar on both the html/body elements and specify overflow-y: hidden on the body element to remove the inner-vertical scrollbar generated. This will preserve the outer horizontal scrollbar on the html element.

How to remove overflow: auto property?

if you want a behavior when clicking, state it in the "onclick" field of the element (div, span, img, a...).

if you want this behavior to modify a style property, set this.style.PROPERTY accordingly.

->

<div onclick="this.style.overflow='visible';">

jQuery .css(left) returns auto instead of actual value in Chrome

As discussed in the comments, setting left to auto for a position: static sounds somehow right, seeing as left has no meaning in the context.

As to why Chrome and IE return different values: .css() provides a unified gateway to the browsers' computed style functions, but it doesn't unify the way the browsers actually compute the style. It's not uncommon for browsers to decide such edge cases differently.

As to why jQuery 1.4.2 and 1.4.3 do this differently, I do not know for sure, but there's this in 1.4.3's release notes:

Nearly the entire CSS module has been rewritten focusing entirely on extensibility. You can now write custom CSS plugins that extend the functionality provided by .css() and .animate().

Why does getComputedStyle return 'auto' for pixels values right after element creation?

There are a couple of things that can cause a result of "auto". You found one of them; display: none. If an element is inline it will also return auto.

Essentially it must be a block or inline-block element and it must be rendered.

Firefox getComputedStyle returns auto

Looks like your element has position: static. Any other type of positioning seems to be computed correctly. Here's a test for a static element:

document.getElementById('results').innerHTML = window.getComputedStyle(document.getElementById('element')).top;
#element {  top : auto;  }
<div id="element"></div><pre id="results"></pre>

Changing the return value of a constructor

A class constructor returns the value of this when it gets called by the new keyword.

See What is the 'new' keyword in JavaScript? and How does the new operator work in JavaScript? for details.

Can we change the return value to something else?

Yes, as long as it is an object, you can override the default by using return - as you did in your example code. See What values can a constructor return to avoid returning this? and What is returned from a constructor? for how that works exactly.

If yes, is it a bad practice?

Yes. Having new Car return a function and not a Car instance is weird and unexpected. People do not do this every day, and they shouldn't start doing it :-)

The only exception is the singleton pattern (which of course is problematic itself), where the constructor may return the singleton instance instead of a new one. (There are however other ways to write JS code for creating singletons, which avoid constructors altogether.)

How to get property value from IEnumerableobject

The type of:

new { property = x.Name, value = x.GetValue(obj) }

is an anonymous type and you can't access fields or properties of that anonymous type outside of the function where it was defined, without using reflection. Here's how you would access its properties using reflection:

foreach (object prop in GetProps(obj))
{
string propertyName = prop.GetType().GetProperty("property").GetValue(prop);
object propertyValue = prop.GetType().GetProperty("value").GetValue(prop);
}

But that's not really the best solution. You don't care about the property value, since you're just returning ones where it's null. So a better solution is IEnumerable<string>:

public static IEnumerable<string> GetProps<T>(T obj)
{
var result = obj.GetType().GetProperties()
.Select(x => new { property = x.Name, value = x.GetValue(obj) })
.Where(x => x.value == null)
.Select(x => x.property)
.ToList();
return result;
}

If you really want to return the property name with its value, I suggest using ValueTuple syntax instead of anonymous types, which will let you access the property and value fields of the ValueTuple (requires C# 7):

public static IEnumerable<(string property, object value)> GetProps<T>(T obj)
{
var result = obj.GetType().GetProperties()
.Select(x => ( x.Name, x.GetValue(obj) ) })
.Where(x => x.Item2 == null)
.ToList();
return result;
}

Javascript - window.getComputedStyle returns auto as element top and left properties

The getComputedStyle method returns the resolved value of CSS properties.

If the style sheet author(you) did not specify values for certain CSS properties(ie: top, right, bottom, and left) then the resolved value returned will be the default value. These CSS properties all have a default value of "auto".

If you cannot or don't want to specify a value yourself in the stylesheet and you only need coordinates relative to the top-left of the viewport, consider using Element.getBoundingClientRect():

<html><head>    <title>Test</title>    <style>        /* Remove default styling to ensure a top and left value of 0 */        body {margin:0; padding:0}        button {display:block}    </style>    <script type="text/javascript">        function test() {            var button = document.getElementsByTagName("button")[0],                style = window.getComputedStyle(button),                coordinates = button.getBoundingClientRect();
alert ( "top = " + coordinates.top + "\nleft = " + coordinates.left + "\nwidth = " + style.width + //63px "\nheight = " + style.height //24px ); } </script></head><body> <button id="buttonTest" onClick="test()" >Test it!</button></body></html>

What is the best way to give a C# auto-property an initial value?

In C# 5 and earlier, to give auto implemented properties an initial value, you have to do it in a constructor.

Since C# 6.0, you can specify initial value in-line. The syntax is:

public int X { get; set; } = x; // C# 6 or higher

DefaultValueAttribute is intended to be used by the VS designer (or any other consumer) to specify a default value, not an initial value. (Even if in designed object, initial value is the default value).

At compile time DefaultValueAttribute will not impact the generated IL and it will not be read to initialize the property to that value (see DefaultValue attribute is not working with my Auto Property).

Example of attributes that impact the IL are ThreadStaticAttribute, CallerMemberNameAttribute, ...



Related Topics



Leave a reply



Submit