简体   繁体   English

如何控制页面上的#id链接?

[英]How to control #id link on a page?

This FIDDLE will explain more than my words 这个FILDLE不仅会解释我的话

How to avoid hidden Title when click on Link id 2 , Link id 3 and Link id 4 ? 单击链接ID 2链接ID 3链接ID 4时如何避免隐藏标题?

PS: Please if anyone have a better Name for this question, please help, my English is not that good! PS:如果有人对这个问题有更好的名字,请帮忙,我的英语不好!

<header id="header">
   header
</header>

<div class="catalog">
    <div class="col1">
       <ul>
           <li><a href="#id1">Link id 1</a></li>
           <li><a href="#id2">Link id 2</a></li>
           <li><a href="#id3">Link id 3</a></li>
           <li><a href="#id4">Link id 4</a></li>
           <li><a href="#id5">Link id 5</a></li>

       </ul>
    </div>
    <div class="col_alternativ"></div>
    <div class="col2">
        <div id="id1" class="item">
            <h2>Link id 1</h2>            
        </div>
        <div id="id2" class="item">
            <h2>Link id 2</h2>            
        </div>
        <div id="id3" class="item">
            <h2>Link id 3</h2>            
        </div>
        <div id="id4" class="item">
            <h2>Link id 4</h2>            
        </div>
        <div id="id5" class="item">
            <h2>Link id 5</h2>            
        </div>
    </div>
</div>


$(window).scroll(function() {    
                var newValue = {opacity : 100}
                var scroll = $(window).scrollTop();
                if (scroll >= 100) {
                    $("#header").addClass("stablemenu").animate(newValue, 1000);
                    $(".col1").addClass("stable_col1").animate(newValue, 1000);
                    $(".col_alternativ").css({"display":"inline-block"});
                } else {
                    $("#header").removeClass("stablemenu");
                    $(".col1").removeClass("stable_col1").animate(newValue, 1000);
                    $(".col_alternativ").css({"display":"none"});
                }
            });

I was able to do what you wanted... I think. 我能够做你想要的...我想。 See here: http://jsfiddle.net/wilsonjonash/tdz3H/8/ 看到这里: http : //jsfiddle.net/wilsonjonash/tdz3H/8/

Edit: Here's the code 编辑:这是代码

<header id="header">
   header
</header>

<div class="catalog">
    <div class="col1">
       <ul>
           <li><a href="#id1">Link id 1</a></li>
           <li><a href="#id2">Link id 2</a></li>
           <li><a href="#id3">Link id 3</a></li>
           <li><a href="#id4">Link id 4</a></li>
           <li><a href="#id5">Link id 5</a></li>

       </ul>
    </div>
    <div class="col_alternativ"></div>
    <div class="col2">
        <div class="item">
            <div id="id1" class="hederid"></div>
            <h2>Link id 1</h2>            
        </div>
        <div class="item">
            <div id="id2" class="hederid"></div>
            <h2>Link id 2</h2>            
        </div>
        <div class="item">
            <div id="id3" class="hederid"></div>
            <h2 id="id3">Link id 3</h2>            
        </div>
        <div class="item">
            <div id="id4" class="hederid"></div>
            <h2>Link id 4</h2>            
        </div>
        <div class="item">
            <div id="id5" class="hederid"></div>
            <h2>Link id 5</h2>            
        </div>
    </div>
</div>

CSS: CSS:

#header {
    width: 100%;
    height: 100px;
    background-color: red;
}
.stablemenu {
    position: fixed;
    top: 0px;
    left:0px;
    z-index: 2;
    background-color: yellow !important;
}
.catalog {
    display: block;
    width: 100%;
    margin-top: 40px;
}
.catalog .col1 {
    display: inline-block;
    border: 1px solid #ccc;
    width: 25%;
    height: auto;
    padding: 1%;
    margin-right: 1%;
}
.catalog .col_alternativ {
    border: 1px solid #fff;
    width: 25%;
    height: auto;
    padding: 1%;
    margin-right: 1%;
    display: none;
}
.stable_col1 {
    position: fixed;
    top: 140px;
    left: 0px;
}
.catalog .col2 {
    display: inline-block;
    width: 70%;
    height: auto;
    vertical-align: top;
}
.item {
    border: 1px solid #ccc;
    width: auto;
    height: 300px;
    margin-bottom: 40px;
    position: relative;
}
.item .hederid {
    position: absolute;
    background: #ccc;
    width: 20px;
    height: 20px;
    left: 0px;
    top: -140px;
}

JavaScript: JavaScript的:

$(window).scroll(function() {    
    var newValue = {opacity : 100}
    var scroll = $(window).scrollTop();
    if (scroll >= 100) {
        $("#header").addClass("stablemenu").animate(newValue, 1000);
        $(".col1").addClass("stable_col1").animate(newValue, 1000);
        $(".col_alternativ").css({"display":"inline-block"});
        $('.col2').css('margin-top','100px');
        //$("#topbar").show().animate(newValue, 1000);
    } else {
        $("#header").removeClass("stablemenu");
        $(".col1").removeClass("stable_col1").animate(newValue, 1000);
        $(".col_alternativ").css({"display":"none"});
        $('.col2').css('margin-top','0');
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果使用jQuery在母版页中呈现控件,如何获取控件ID? - How to get control id if control is rendered inside of master page with jQuery? 如何使用javascript在用户控制页面的父页面中获取隐藏的控件ID - How can i get hidden control id in parent page in the user control page using javascript 如何在 React Hooks 和 useRouteMatch 中创建将用户发送到 id 页面的链接 - how to create a link that send the user to the id page in React Hooks and useRouteMatch 如何使用ahref链接引用另一个页面ID? - How to reference to another page id using ahref link? 点击链接后如何通过id触发另一个页面的onclick? - After click link how to trigger onclick on another page by id? 创建指向刷新页面的ID的链接 - Creating a link to an id that refreshes the page 从页面上的链接获取ID - Get ID from link on the page 如何在不更改链接的情况下在同一 php 页面上的分页链接按钮上传递 id? - How to pass id on pagination link button on same php page without link change? Angular - 如何从一个页面链接到另一个页面并在不使用id的情况下滚动到离子中的锚点 - Angular - how to link from one page to another page and scroll to an anchor in ionic without using id JS返回指向其中具有特定ID的页面的链接 - JS return a link to the page with certain ID in it
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM