当用户向下滚动页面时显示隐藏的div

时间:2015-10-11 15:38:00

标签: javascript jquery html css twitter-bootstrap

< p>当您滚过它时,我有一个导航栏粘在页面顶部。 当此导航栏固定在页面顶部时,我希望显示一个徽标。 徽标位于div#navlogo内。< / p> < p>我目前将#navlogo设置为display:none。我想当你滚动超过100px时,它的显示需要设置为显示块或类似的东西。< / p> < p>我尝试过一些东西,但我不擅长java并且没有运气。< / p> < p>< a href =" https://jsfiddle.net/gx25ospo/2/" rel =" nofollow">您可以在这里查看JSFIDDLE< / a>< / p> < p>这是我用来将导航栏设置为固定< / p>的脚本 < pre>< code> $(window).scroll(function(){     var nav = $(' #custom-bootstrap-menu');     var body = $(' body');     var top = 100;     if($(window).scrollTop()> = top){         nav.addClass(' Navbar的固​​定顶&#39);         body.addClass('填充-50&#39);     } else {         nav.removeClass(' Navbar的固​​定顶&#39);         body.removeClass('填充-50&#39);     } }); < /代码>< /预> < p>和一点点css< / p> < pre>< code> #logo {     身高:100px; } .padding-fifty {   padding-top:50px; } #navlogo {     display:none; } < /代码>< /预> < p>如您所见,它将导航设置为固定,并通过添加50px来补偿页面偏移。我需要一些将#navlogo设置为可见的东西。任何人都可以提供一些帮助吗?< / p> < p>非常感谢您的帮助!< / p>

3 个答案:

答案 0 :(得分:0)

您可以在Javascript中设置css display属性:

var logo = $('div#navlogo');
logo.css('display', 'block');

例如:https://jsfiddle.net/gx25ospo/3/

答案 1 :(得分:0)

最后尝试将此样式添加到CSS中:

.navbar-fixed-top #navlogo {
    display:block;
}

答案 2 :(得分:0)

试试这个https://jsfiddle.net/gx25ospo/4/

PHP Warning:  file_get_contents(http://www.oref.org.il/WarningMessages/Alert/alerts.json?v=1444534443): failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found
 in /home/dupdates/domains/dupdates.com/public_html/systems/history/script.php on line 60
PHP Warning:  file_get_contents(http://www.oref.org.il/WarningMessages/Alert/alerts.json?v=1444534445): failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found
 in /home/dupdates/domains/dupdates.com/public_html/systems/history/script.php on line 60
PHP Warning:  file_get_contents(http://www.oref.org.il/WarningMessages/Alert/alerts.json?v=1444534447): failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found
 in /home/dupdates/domains/dupdates.com/public_html/systems/history/script.php on line 60
PHP Warning:  file_get_contents(http://www.oref.org.il/WarningMessages/Alert/alerts.json?v=1444534449): failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found
 in /home/dupdates/domains/dupdates.com/public_html/systems/history/script.php on line 60
PHP Warning:  file_get_contents(http://www.oref.org.il/WarningMessages/Alert/alerts.json?v=1444534451): failed to open stream: Redirection limit reached, aborting in /home/dupdates/domains/dupdates.com/public_html/systems/history/script.php on line 60
PHP Warning:  file_get_contents(http://www.oref.org.il/WarningMessages/Alert/alerts.json?v=1444534454): failed to open stream: Redirection limit reached, aborting in /home/dupdates/domains/dupdates.com/public_html/systems/history/script.php on line 60
PHP Warning:  file_get_contents(http://www.oref.org.il/WarningMessages/Alert/alerts.json?v=1444534456): failed to open stream: Redirection limit reached, aborting in /home/dupdates/domains/dupdates.com/public_html/systems/history/script.php on line 60
PHP Warning:  file_get_contents(http://www.oref.org.il/WarningMessages/Alert/alerts.json?v=1444534458): failed to open stream: Redirection limit reached, aborting in /home/dupdates/domains/dupdates.com/public_html/systems/history/script.php on line 60
PHP Warning:  file_get_contents(http://www.oref.org.il/WarningMessages/Alert/alerts.json?v=1444534460): failed to open stream: Redirection limit reached, aborting in /home/dupdates/domains/dupdates.com/public_html/systems/history/script.php on line 60
PHP Warning:  file_get_contents(http://www.oref.org.il/WarningMessages/Alert/alerts.json?v=1444534462): failed to open stream: Redirection limit reached, aborting in /home/dupdates/domains/dupdates.com/public_html/systems/history/script.php on line 60
PHP Warning:  file_get_contents(http://www.oref.org.il/WarningMessages/Alert/alerts.json?v=1444534464): failed to open stream: Redirection limit reached, aborting in /home/dupdates/domains/dupdates.com/public_html/systems/history/script.php on line 60
PHP Warning:  file_get_contents(http://www.oref.org.il/WarningMessages/Alert/alerts.json?v=1444534466): failed to open stream: Redirection limit reached, aborting in /home/dupdates/domains/dupdates.com/public_html/systems/history/script.php on line 60
PHP Warning:  file_get_contents(http://www.oref.org.il/WarningMessages/Alert/alerts.json?v=1444534468): failed to open stream: Redirection limit reached, aborting in /home/dupdates/domains/dupdates.com/public_html/systems/history/script.php on line 60
PHP Warning:  file_get_contents(http://www.oref.org.il/WarningMessages/Alert/alerts.json?v=1444534470): failed to open stream: Redirection limit reached, aborting in /home/dupdates/domains/dupdates.com/public_html/systems/history/script.php on line 60
PHP Warning:  file_get_contents(http://www.oref.org.il/WarningMessages/Alert/alerts.json?v=1444534500): failed to open stream: Redirection limit reached, aborting in /home/dupdates/domains/dupdates.com/public_html/systems/history/script.php on line 60
PHP Warning:  file_get_contents(http://www.oref.org.il/WarningMessages/Alert/alerts.json?v=1444534502): failed to open stream: Redirection limit reached, aborting in /home/dupdates/domains/dupdates.com/public_html/systems/history/script.php on line 60

JS

.navbar-brand {
display: none;
}

.visible {
display: block;
}
相关问题