每个链接菜单下方的进度条

时间:2012-07-24 16:32:50

标签: javascript jquery html css css3

我正在寻找帮助来创建像This is the menu i want

这样的菜单

可以使用Javascript或Jquery吗?

我用html和css做了这样的菜单,但它和网站不一样。

我有2个选项

这是第一个代码,但问题是如果我点击网站的其他内容就会失去进度条......

body {
    padding: 10em 0 0;
}
.ui-menu {
    width: 37em;
    padding: 0;
    text-align: center;
}
.ui-menu a {
    width: 4em;
    margin: 0 .15em;
    padding: .1em .35em;
    display: inline-block;
    background: #f7f7f7;
    font: 17px "Arial Narrow", sans-serif;
    text-align: center;
    text-decoration: none;
}
.ui-menu a:focus {
    outline: none;
}
.ui-menu-bottom-line {
    width: 35em;
    height: 1px;
    margin: 1em auto;
    background: #d7d7d7
        linear-gradient(left, #d82126 50%, transparent 50%) no-repeat;
    background-size: 5em;
    transition: 1s; 
}
.ui-menu a:nth-child(2):focus ~ .ui-menu-bottom-line,
.ui-menu a:nth-child(2):active ~ .ui-menu-bottom-line {
    background-size: 15em;
}
.ui-menu a:nth-child(3):focus ~ .ui-menu-bottom-line,
.ui-menu a:nth-child(3):active ~ .ui-menu-bottom-line {
    background-size: 25em;
}
.ui-menu a:nth-child(4):focus ~ .ui-menu-bottom-line,
.ui-menu a:nth-child(4):active ~ .ui-menu-bottom-line {
    background-size: 35em;
}
.ui-menu a:nth-child(5):focus ~ .ui-menu-bottom-line,
.ui-menu a:nth-child(5):active ~ .ui-menu-bottom-line {
    background-size: 45em;
}
.ui-menu a:nth-child(6):focus ~ .ui-menu-bottom-line,
.ui-menu a:nth-child(6):active ~ .ui-menu-bottom-line {
    background-size: 55em;
}
.ui-menu a:nth-child(7):focus ~ .ui-menu-bottom-line,
.ui-menu a:nth-child(7):active ~ .ui-menu-bottom-line {
    background-size: 65em;
}

和HTML:

<div class="ui-menu">
<a class="goto-frame" href="#" tabindex="1">Welcome</a><a class="goto-frame" href="#" tabindex="1">Problem</a><a class="goto-frame" href="#solution" tabindex="1">
Solution</a><a class="goto-frame" href="#team" tabindex="1">Team</a><a class="goto-frame" href="#traction" tabindex="1">Traction
</a><a class="goto-frame" href="#product" tabindex="1">Product</a><a class="goto-frame" href="#contact" tabindex="1">Contact</a>
<div class="ui-menu-bottom-line"></div>

第二个代码:

body {
    padding: 10em 0 0;
}
.ui-menu {
    width: 37em;
    padding: 0;
    font: 17px "Arial Narrow", sans-serif;
    text-align: center;
}
.ui-menu input[type=radio] { display: none; }
.ui-menu label {
    width: 4em;
    margin: 0;
    padding: .1em .5em;
    display: inline-block;
    text-align: center;
}
.ui-menu-bottom-line {
    width: 35em;
    height: 1px;
    margin: 1em auto;
    background: #d7d7d7
        linear-gradient(left, #d82126 50%, transparent 50%) no-repeat;
    background-size: 5em;
    transition: 1s;
}
.ui-menu #welcome:checked ~ .ui-menu-bottom-line {
    background-size: 5em;
}
.ui-menu #problem:checked ~ .ui-menu-bottom-line {
    background-size: 15em;
}
.ui-menu #solution:checked ~ .ui-menu-bottom-line {
    background-size: 25em;
}
.ui-menu #team:checked ~ .ui-menu-bottom-line {
    background-size: 35em;
}
.ui-menu #traction:checked ~ .ui-menu-bottom-line {
    background-size: 45em;
}
.ui-menu #product:checked ~ .ui-menu-bottom-line {
    background-size: 55em;
}
.ui-menu #contact ~ .ui-menu-bottom-line {
    background-size: 65em;
}

和HTML:

<div class="ui-menu">
<input type="radio" name="mi" id="welcome">
<label class="goto-frame" for="welcome">Welcome</label>
<input type="radio" name="mi" id="problem">
<label class="goto-frame" for="problem">Problem</label>
<input type="radio" name="mi" id="solution">
<label class="goto-frame" for="solution">Solution</label>
<input type="radio" name="mi" id="team">
<label class="goto-frame" for="team">Team</label>
<input type="radio" name="mi" id="traction">
<label class="goto-frame" for="traction">Traction</label>
<input type="radio" name="mi" id="product">
<label class="goto-frame" for="product">Product</label>
<input type="radio" name="mi" id="contact">
<label class="goto-frame" for="contact">Contact</label>
<div class="ui-menu-bottom-line"></div>

我怎样才能像piccsy.com/investors这样的菜单? JavaScript的? jQuery的? HTML + CSS ??

提前谢谢大家。

1 个答案:

答案 0 :(得分:1)

您可以安装firebug或inspect元素以查看事情是如何完成的。在这种情况下,您的进度条包含两项内容:灰线和上面的红线(实际为div)。滚动或单击导航时,将有一个脚本可以更改红条宽度,以便您可以看到进度。 因此,您的脚本必须处理两件事:滚动事件并单击导航事件。

示例:

function updateProgress(){
   $('#progress').width(maxWidth * ($(body).scrollTop() / $(body).height()) );
}

$('#Nav1').click(function(){
   //Scroll to a position
   $(body).scrollTo(100);
});

$(body).scroll(function(){
   updateProgress()
});

类似的东西