【问题标题】:Divs Appear Anytime User Scrolls - Not When In ViewDivs 会在用户滚动时出现 - 不在视图中
【发布时间】:2017-08-29 19:00:47
【问题描述】:

所以,我正在开发我的投资组合网站,但我的条形图遇到了一些问题。我正在尝试将其设置为在滚动时出现。到目前为止,我已经能够实现正常工作的效果,但是只要用户滚动它就会这样做 - 而不是当它进入视野时。我做错了什么?另外,我应该注意我正在为我的网站使用一个名为 LiveQuery 的插件。

HTML:

<div id="section-three">
        <div id="web-head">
            <h2>Web Development</h2>
            <br>
            <p><i>Code, code, and more code!</i></p>
        </div>
        <div id="web-graph">
            <div id="html-bar">
                <p>HTML</p>
                <div id="html">
                </div>
                <div class="clear"></div>
            </div>

            <div id="css-bar">
                <p>CSS</p>
                <div id="css">
                </div>
                <div class="clear"></div>
            </div>

            <div id="jq-bar">
                <p>JQuery/JavaScript</p>
                <div id="jq">
                </div>
                <div class="clear"></div>
            </div>
        </div>
    </div>

CSS:

    /*SECTION THREE CODE*/

#section-three {
    min-width: 100vw;
    width: 100%;
    min-height: 500px;
    height: 100%;
    background-color: #000000;
    overflow: hidden;
    text-align: center;
}

#web-head {
    max-width: 70vw;
    width: 100%;
    min-height: 100px;
    height: 100%;
    margin-top: 2%;
    margin-left: auto;
    margin-right: auto;
    color: white;
}

#web-head h2 {
    font-weight: normal;
}

#web-head p {
    color: #808080;
}

#web-graph {
    min-width: 85vw;
    width: 100%;
    min-height: 300px;
    height: 100%;
    display: flex;
    flex-direction: column;
    text-align: left;
}

#web-graph p {
    float: left;
    max-width: 14vw;
    width: 100%;
    min-height: 50px;
    height: 100%;
    margin-left: 2%;
    margin-top: 37.5px;
    color: white;
}

#html-bar {
    flex: 1;
}

#html {
    min-height: 50px;
    height: 100%;
    max-width: 70vw;
    width: 0;
    float: left;
    margin-top: 25px;
}

#html.active {
    background-color: #808080;
    transition: all ease-in-out 1s;
    min-height: 50px;
    height: 100%;
    max-width: 70vw;
    width: 70%;
    float: left;
    margin-top: 25px;
}

#css-bar {
    flex: 1;
}

#css {
    min-height: 50px;
    height: 100%;
    max-width: 70vw;
    width: 0;
    float: left;
    margin-top: 25px;
}

#css.active {
    background-color: #808080;
    transition: all ease-in-out 1s;
    min-height: 50px;
    height: 100%;
    max-width: 65vw;
    width: 65%;
    float: left;
    margin-top: 25px;
}

#jq-bar {
    flex: 1;
}

#jq {
    min-height: 50px;
    height: 100%;
    max-width: 70vw;
    width: 0;
    float: left;
    margin-top: 25px;
}

#jq.active {
    background-color: #808080;
    transition: all ease-in-out 1s;
    min-height: 40px;
    height: 100%;
    max-width: 35vw;
    width: 35%;
    float: left;
    margin-top: 25px;
}

JQuery:

    $(document).ready(function () {
    $('#jq-bar:visible').livequery(function () {
        $('#html').addClass('active');
        $('#css').addClass('active');
        $('#jq').addClass('active');
    })             
});

我还应该注意,我之前曾尝试将它链接到每当显示具有特定 ID 或类的 div 或项目时,它会触发该功能,但不幸的是,它仍然不起作用。如果有人能够指出我正确的方向,我将不胜感激。谢谢!

【问题讨论】:

    标签: jquery html css scroll


    【解决方案1】:

    您的选择器会在页面加载时立即选择元素:

     $(document).ready(function () {
        $('#jq-bar:visible')
    

    无耻从W3C盗取:

    定义和用法 :visible 选择器选择每个元素 当前可见。

    可见元素是不存在的元素:
    设置为显示:无
    type="hidden" 的表单元素
    宽度和高度设置为 0
    隐藏的父元素(这也隐藏了子元素)

    如果您尝试跟踪某些东西何时可见,您可以尝试使用滚动顶部之类的东西来初始化类。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-30
      • 2012-06-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多