简体   繁体   English

在移动视口上隐藏居中徽标

[英]Hide a Centered Logo on Mobile Viewport

So I am working on a site and the logo is centered on the navbar at the bottom of the page as list item. 因此,我在一个网站上工作,徽标位于列表底部页面底部的导航栏上。 When the site collapses to mobile i want to hide it. 当网站崩溃到移动设备时,我想将其隐藏。 I've tried display:none and hidden but cant figure it out. 我尝试过display:none和hidden,但无法弄清楚。 If you can see an easier way to have a bottom nav that scrolls up with a centered logo I will take it lol 如果您能看到一种更简单的方法,使底部导航栏上滚动并带有居中徽标,则我将其大声笑

 (function($) { var defaults = { topSpacing: 0, bottomSpacing: 0, className: 'is-sticky', wrapperClassName: 'sticky-wrapper', center: false, getWidthFrom: '', responsiveWidth: false }, $window = $(window), $document = $(document), sticked = [], windowHeight = $window.height(), scroller = function() { var scrollTop = $window.scrollTop(), documentHeight = $document.height(), dwh = documentHeight - windowHeight, extra = (scrollTop > dwh) ? dwh - scrollTop : 0; for (var i = 0; i < sticked.length; i++) { var s = sticked[i], elementTop = s.stickyWrapper.offset().top, etse = elementTop - s.topSpacing - extra; if (scrollTop <= etse) { if (s.currentTop !== null) { s.stickyElement .css('position', '') .css('top', ''); s.stickyElement.trigger('sticky-end', [s]).parent().removeClass(s.className); s.currentTop = null; } } else { var newTop = documentHeight - s.stickyElement.outerHeight() - s.topSpacing - s.bottomSpacing - scrollTop - extra; if (newTop < 0) { newTop = newTop + s.topSpacing; } else { newTop = s.topSpacing; } if (s.currentTop != newTop) { s.stickyElement .css('position', 'fixed') .css('top', newTop); if (typeof s.getWidthFrom !== 'undefined') { s.stickyElement.css('width', $(s.getWidthFrom).width()); } s.stickyElement.trigger('sticky-start', [s]).parent().addClass(s.className); s.currentTop = newTop; } } } }, resizer = function() { windowHeight = $window.height(); for (var i = 0; i < sticked.length; i++) { var s = sticked[i]; if (typeof s.getWidthFrom !== 'undefined' && s.responsiveWidth === true) { s.stickyElement.css('width', $(s.getWidthFrom).width()); } } }, methods = { init: function(options) { var o = $.extend({}, defaults, options); return this.each(function() { var stickyElement = $(this); var stickyId = stickyElement.attr('id'); var wrapperId = stickyId ? stickyId + '-' + defaults.wrapperClassName : defaults.wrapperClassName var wrapper = $('<div></div>') .attr('id', stickyId + '-sticky-wrapper') .addClass(o.wrapperClassName); stickyElement.wrapAll(wrapper); if (o.center) { stickyElement.parent().css({width:stickyElement.outerWidth(),marginLeft:"auto",marginRight:"auto"}); } if (stickyElement.css("float") == "right") { stickyElement.css({"float":"none"}).parent().css({"float":"right"}); } var stickyWrapper = stickyElement.parent(); stickyWrapper.css('height', stickyElement.outerHeight()); sticked.push({ topSpacing: o.topSpacing, bottomSpacing: o.bottomSpacing, stickyElement: stickyElement, currentTop: null, stickyWrapper: stickyWrapper, className: o.className, getWidthFrom: o.getWidthFrom, responsiveWidth: o.responsiveWidth }); }); }, update: scroller, unstick: function(options) { return this.each(function() { var unstickyElement = $(this); var removeIdx = -1; for (var i = 0; i < sticked.length; i++) { if (sticked[i].stickyElement.get(0) == unstickyElement.get(0)) { removeIdx = i; } } if(removeIdx != -1) { sticked.splice(removeIdx,1); unstickyElement.unwrap(); unstickyElement.removeAttr('style'); } }); } }; // should be more efficient than using $window.scroll(scroller) and $window.resize(resizer): if (window.addEventListener) { window.addEventListener('scroll', scroller, false); window.addEventListener('resize', resizer, false); } else if (window.attachEvent) { window.attachEvent('onscroll', scroller); window.attachEvent('onresize', resizer); } $.fn.sticky = function(method) { if (methods[method]) { return methods[method].apply(this, Array.prototype.slice.call(arguments, 1)); } else if (typeof method === 'object' || !method ) { return methods.init.apply( this, arguments ); } else { $.error('Method ' + method + ' does not exist on jQuery.sticky'); } }; $.fn.unstick = function(method) { if (methods[method]) { return methods[method].apply(this, Array.prototype.slice.call(arguments, 1)); } else if (typeof method === 'object' || !method ) { return methods.unstick.apply( this, arguments ); } else { $.error('Method ' + method + ' does not exist on jQuery.sticky'); } }; $(function() { setTimeout(scroller, 0); }); })(jQuery); 
 .section-menu{ z-index: 9999; } .navbar-default{ background: #141414; border: 0px; border-radius: 0px; } .navbar-default .navbar-nav > li > a{ text-transform: uppercase; font-weight: 700; padding: 10px; font-size: 16px; font-family: 'Roboto', serif; color: #fff; line-height: 30px; } .navbar-default .navbar-nav > li > a:hover,.navbar-default .navbar-nav > li > a:focus{ color: #7f1f1f; } .main-nav{ width: 100%; margin: 0 auto; } .navbar-default .navbar-nav > .active > a, .navbar-default .navbar-nav > .active > a:focus, .navbar-default .navbar-nav > .active > a:hover { color: #fcb027; background-color: transparent; } #navbar-primary .navbar-nav { width: 100%; text-align: center; } #navbar-primary .navbar-nav > li { display: inline-block; float: none; } #navbar-primary .navbar-nav > li > a { padding-left: 30px; padding-right: 30px; } @media only screen and (max-width: 1080px) { .logo{ display: none; } } 
 <body data-spy="scroll" data-target=".main-nav"> <section id="section-banner"> <div class="container"> <div class="row"> <div class="banner-content text-center"> <h2 class="title"> <div class="line-top"></div> Twitch Streamer & Web Designer <div class="line-btm"></div> </h2> <a href="#" class="btn btn-default">Learn More</a> </div> </div> </div> </section> <!-- Navagation Starts --> <section class="section-menu"> <div id="navbar-primary" class="navbar navbar-default main-nav" role="navigation" > <div class="container" > <div class="navbar-header"> <button type= "button" class="navbar-toggle collapsed" data-target="#bs-example-navbar-collapse-1" data-toggle="collapse"> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> </div><!-- navbar-header end --> <!-- main nav --> <div class="collapse navbar-collapse navigation" id="bs-example-navbar-collapse-1" role="navigation"> <ul class="nav navbar-nav"> <li class="active"><a href="index.html">Home</a></li> <li><a href="channel.html">Channel</a></li> <li><a href="games.html">Games</a></li> <li class="logo"><a href="index.html"><img src="assets/images/logo.png" alt=""></a></li> <li><a href="news.html">News</a></li> <li><a href="faq.html">FAQ</a></li> <li><a href="contact.html">Contact</a></li> </ul> </div><!-- /.navbar-collapse --> </div><!-- /.container-fluid --> </div> </section> 

使用bootstrap的hidden-xs助手类

<li class="logo hidden-xs"><a href="index.html"><img src="assets/images/logo.png" alt=""></a></li>

Just change display: none; 只是更改display: none; to visibility: hidden; visibility: hidden;

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM