Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define overflow-y?

Tags:

jquery

css

I don't understand why it doesn't like my overflow-y syntax?

enter image description here

function show_modal(target){
    $(target).modal({
        backdrop: true,
        keyboard: true
    }).css({
        width: 'auto',
        overflow-y: 'hidden',
        'margin-left': function () {
            return -($(this).width() / 2);
        }
    });
    $(target).modal('show');
}
like image 281
Houman Avatar asked Dec 18 '25 14:12

Houman


2 Answers

The DOM exposes CSS properties as camelcased versions of themselves. Try using overflowY instead.

As a general note, to put a hyphen in an object key name, you need to use quotes:

{
    "width": 'auto',
    "overflow-y": 'hidden',
    "margin-left": function () {
        return -($(this).width() / 2);
    }
}

I am not sure if jQuery automatically maps the CSS names to the corresponding DOM versions, so it is best to use overflowY instead.

As Chris Heald has pointed out, jQuery does in fact accept the hyphenated property name as well as the camel cased one, so either of overflow-y (provided you use quotes) or overflowY should work.

overflow-y is overflow minus y, which is a syntax error since the key part of an object literal must be either an identifier, a string literal, or a numeric literal, not an expression. To use the overflow-y property, you can quote the property name into a string literal like so: 'overflow-y': 'hidden',

like image 27
Lie Ryan Avatar answered Dec 20 '25 02:12

Lie Ryan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!