-1

我有一个简单的菜单,里面有 uls,我想在页面到达 div(在内容中)时更改 ul 的样式(使用 css),我的意思是滚动并到达那个 div。例如,我有这个代码:

css 文件

#menu {
    background-color: #ccc;
    width:100%;
}

.menutext {
    padding:25 40 30 !important;
    display:inline-block;
}

.menutext2 {
    padding:25 40 0 !important;
    display:inline-block;
    color:red;
}

.alldivs {
    width:300px;
    height:200px;
    background-color:a9a9a9;
}

HTML

<div id="menu">
    <div class="menutext">Change the style of me to .mebutext2 on arriving to DIV1</div>
    <div class="menutext">Change the style of me to .mebutext2 on arriving to DIV2</div>
    <div class="menutext">Change the style of me to .mebutext2 on arriving to DIV3</div>
</div>

<br><br><br>

<div class="alldivs"><div id="DIV1">DIV1</div></div>
<br><br><br><br>
<div class="alldivs"><div id="DIV2">DIV2</div></div>
<br><br><br><br>
<div class="alldivs"><div id="DIV3">DIV3</div></div>
<br><br><br><br>

这是我的代码http://jsfiddle.net/vu7Hh/

很快:当我滚动并到达 DIV2 的顶部时,例如菜单样式中的第二个 ul 更改为 .menustyle2(换句话说,它变为红色)。所以我认为我应该在这里使用 jQuery 来做到这一点。

4

0 回答 0