最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

css - Setting the overflow property with Javascript - Stack Overflow

programmeradmin3浏览0评论

i need this function to enable vertical scrolling but not horizontal.

This doesn't works:

function scrollFunction() {
        // Scroll to top 
    document.getElementsByTagName('body')[0].style.overflow-y='auto';
}

While this does, but it enables both vertical and horizontal scrolling.

function scrollFunction() {
    // Scroll to top
    document.getElementsByTagName('body')[0].style.overflow='auto';
}

How can I specify just the overflow-y properly? Thanks

i need this function to enable vertical scrolling but not horizontal.

This doesn't works:

function scrollFunction() {
        // Scroll to top 
    document.getElementsByTagName('body')[0].style.overflow-y='auto';
}

While this does, but it enables both vertical and horizontal scrolling.

function scrollFunction() {
    // Scroll to top
    document.getElementsByTagName('body')[0].style.overflow='auto';
}

How can I specify just the overflow-y properly? Thanks

Share Improve this question asked Feb 28, 2013 at 21:16 ChainChain 6273 gold badges9 silver badges24 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 10

Compound style properties are written in camelCase notation (the first letter is small):

document.getElementsByTagName("body")[0].style.overflowY = "auto";

As an alternative to VisioN's answer you can use square brackets and a string to access it:

document.getElementByTagName("body")[0].style['overflow-y'] = "auto";

This is good if you don't know what the camelCase is.

发布评论

评论列表(0)

  1. 暂无评论