缩小导航栏后封面图片(Shrink navbar AFTER cover image)

我正在使用Bootstrap 4从头开始构建一个网站。我们的想法是在顶部有一个带有“固定到位”透明导航栏的全屏封面图像; 这部分很容易,我可以闭着眼睛做很多事情。 我现在试图实现的效果是,当用户向下滚动并打开封面图片的末尾时,导航栏将缩小并粘在顶部。

我发现很多教程和指南都教导了如何在Jquery中实现这一点,但是他们都提供了基本上使代码在'如此多像素'之后缩小的代码(在50以下的例子中)。 我喜欢Jquery在类中添加然后删除类的想法,但是我不确定如何修改它以便在它到达我的封面图像的底部而不是50px时激活。

$(window).scroll(function() {
  if ($(document).scrollTop() > 50) {
    $('nav').addClass('shrink');
  } else {
    $('nav').removeClass('shrink');
  }
});

I'm building a website from scratch using Bootstrap 4. The idea is to have a full screen cover image with a 'fixed in place' transparent navbar at the top; this part is easy and I can pretty much do it with my eyes closed. What I'm trying to now achieve is an effect so when the user scrolls down and hits the end of the cover image, the navbar will shrink down and be sticky at the top.

I've found so many tutorials and guides that teach how to do this in Jquery however they all offer basically the code which is to make it shrink after 'so many pixels' (in the case of the example below its 50). I like the idea of the Jquery adding in a class and then removing the class, however I'm not sure how I can modify so it activates when it hits the bottom of my cover image rather than the 50px.

$(window).scroll(function() {
  if ($(document).scrollTop() > 50) {
    $('nav').addClass('shrink');
  } else {
    $('nav').removeClass('shrink');
  }
});

原文:https://stackoverflow.com/questions/47380079
2022-11-12 19:11

满意答案

一般的答案是“不要这样做”。

除此之外,您可以通过使用性能计数器获得很多收益。 如果内置计数器没有帮助,您可以创建自己的计数器。

除其他外,性能计数器可以让您了解如何通过负载测试重现性能问题。

下一个想法是缩小您感兴趣的区域。如果结果是您的Web服务访问速度很慢,那么对整个应用程序的性能没有任何影响。

接下来,确保已经为您的应用程序进行了检测,最好是使用配置。 企业库日志记录应用程序块非常适用于此,因为它允许您将日志记录添加到应用程序,但将其配置为关闭。 然后,您可以配置要记录的信息类型以及将其记录到何处。

这使您可以选择日志记录的成本,从记录到事件日志到记录到XML文件。 你可以在运行时决定这一切。

最后,您将无法使用dotTrace或其他需要重新启动IIS以及向正在运行的应用程序添加代码的内容。 不在生产中。 上述想法是为了不需要这样做。


The general answer is "don't do it".

Other than that, you can gain a lot by using performance counters. If the built-in counters don't help, you can create your own.

Among other things, the performance counters may give you an idea of how to reproduce the performance problems through load testing.

The next idea is to narrow down the area you're interested in. There's no sense impacting performance for the entire application if it turns out to be your web service access that's slow.

Next, be sure to have instrumented your application, preferably by using configuration. The Enterprise Library Logging Application Block is great for that, as it allows you to add the logging to your application, but have it configured off. Then, you can configure what kind of information to log, and where to log it to.

This gives you choices about how expensive the logging should be, from logging to the event log to logging to an XML file. And you can decided this all at runtime.

Finally, you're not going to be able to use dotTrace or something else that requires restarting IIS an adding code to your running application. Not in production. The ideas above are for the purpose of not needing to do so.

相关问答

更多

如何将ASP.NET Core UserSecrets部署到生产环境(How to deploy ASP.NET Core UserSecrets to production)

不要在生产中使用应用程序秘密。 永远。 正如文章所述,在发展期间。 您如何在生产环境中发布秘密取决于您的生产环境。 Linux,Windows和Azure都支持环境变量 - 这就是你的秘密应该去的地方,使用你的托管服务提供商提供给你的任何UI。 应用程序设置文档更详细地介绍了这一点 Don't use app secrets in production. Ever. As the article says DURING DEVELOPMENT. How you publish secrets in...

ASP.Net工作进程内存配置文件工具(ASP.Net Worker Process Memory Profile Tools)

ANTS Profiler非常擅长分析ASP.NET应用程序。 ANTS Profiler is very good at profiling ASP.NET applications.

ASP.NET MVC RequireHttps仅在生产中(ASP.NET MVC RequireHttps in Production Only)

如果您在开发工作站上运行发布版本,但有条件的编译可以执行此操作,这将无济于事 #if !DEBUG [RequireHttps] //apply to all actions in controller #endif public class SomeController { //... or ... #if !DEBUG [RequireHttps] //apply to this action only #endif public ActionResult SomeA...

在生产中运行的asp.net应用程序正在崩溃(asp.net application running in production is crashing)

WER帮助我解决了这个问题。使用WER启用了故障转储 Windows Registry Editor Version 5.00 �   [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\w3wp.exe] "DumpFolder"=hex(2):63,00,3a,00,5c,00,64,00,75,00,6d,00,70,00,73,00,00,00 "DumpCount"=dword...

无法加载文件或程序集 - 处理本地而不是生产 - ASP.net(Could not load file or assembly - working on local not on production - ASP.net)

结果如下 - 如下所示: 尽管我们已经从项目输出中删除了bin目录并重新构建 - 它没有任何效果 解决方案是清理所有的解决方案,然后重建 显然应该尝试过,但有时你的头脑不工作:) The solution as it turns out - is as follows: although we had deleted the bin directory form the project output and re-built - it had no effect solution was to c...

您如何描述生产ASP.NET应用程序?(How do you profile a production ASP.NET applicaiton?)

一般的答案是“不要这样做”。 除此之外,您可以通过使用性能计数器获得很多收益。 如果内置计数器没有帮助,您可以创建自己的计数器。 除其他外,性能计数器可以让您了解如何通过负载测试重现性能问题。 下一个想法是缩小您感兴趣的区域。如果结果是您的Web服务访问速度很慢,那么对整个应用程序的性能没有任何影响。 接下来,确保已经为您的应用程序进行了检测,最好是使用配置。 企业库日志记录应用程序块非常适用于此,因为它允许您将日志记录添加到应用程序,但将其配置为关闭。 然后,您可以配置要记录的信息类型以及将其记...

在生产中实例化ASP.NET Core应用程序(Instantiation of ASP.NET Core application in production)

无论主机选择ASP.Net核心应用程序(IIS还是通过Kestrel自行托管),在主机进程启动期间,方法Program.Main() , Startup.ConfigureServices()和Startup.Configure()执行一次。 很显然,当你用Kestrel web服务器启动exe文件时, Program.Main()被执行。 但是,在IIS中托管时实际调用它可能并不明显。 实际上是这样。 当ASP.Net核心应用程序与IIS集成时,它通常由dotnet.exe运行程序执行(它也可以...

将生产服务器从ASP.NET 2升级到ASP.NET 4(Upgrade production server from ASP.NET 2 to ASP.NET 4)

使用Web平台安装程序; 它专门用于帮助您准确了解运行所需的内容。 在您的情况下,它将安装完整的.NET 4.0 Framework以及您需要的其他内容,假设您使用它进行正确的选择。 安装您所说的任何组件都不会对现有应用程序做任何事情,只要您不会错误地配置它们,以致不正确地尝试使用新的框架。 所有这些东西默认都是并行工作的。 Use the Web Platform Installer; it's specifically meant to help you get exactly what yo...

在生产应用程序中使用ASP.NET MVC 2 Preview 1是否可行?(Is it viable to use ASP.NET MVC 2 Preview 1 in a production application?)

基于MVC第1版,在最终版本发布之前有很多预览。 最初的ASP.NET MVC 1 Preview 1与最终版本截然不同。 最终的MVC 1预览版5与最终版本非常相似,差别很小(如果有的话),我认为主要区别是错误修复。 虽然MVC 2是对MVC 1的改进,但它确实有一些主要的新举措(例如区域),并且无法保证当前MVC 2预览1的工作方式是最终产品的工作方式。 如果您需要在生产系统中使用寿命,我建议您不要在生产环境中使用任何预览产品,除非您愿意处理最终版本中可能发生的重大变化。 附注...如果您使用...

相关文章

更多

C#中Image.FromFile()的用法

谁能告诉我这个方法的具体用法我是这样写的Image.FromFile("1.jpg&quot ...

微信公众平台开发(91) 右上角按钮/底部导航栏/用户网络状态

隐藏微信中网页右上角按钮 公众号在有需要时(如不需要用户分享某个页面),可在网页中通过JavaScr ...

jquery滚动图片导航与图片放大效果模板

jquery滚动图片导航与图片放大效果模板实现图片左右滚动并放大效果 jquery滚动图片导航效果: ...

加载图片时,相同的路径名,用不同的方法时结果却不一样?

用URL imageUrl = MyText.class.getResource("/res ...

Java添加图片水印

周末在家上围脖,看到sina围脖上图片都有水印,想到Java有专门Image的处理包,同样应该可以实现 ...

微信点击超链接第一次不会有“微信中网页底部导航栏”,进入之后再点击链接就会有了,自己会新建窗口

从微信的消息交互界面点击超链接,会进入一个网页,但是该网页貌似是重定向什么的,相当于不是浏览当前网址吧 ...

如何在jsp中显示数据库的图片

图片在数据库中以连接<image src="">的方式存在.. 我可 ...

几款开源图片剪切插件

imgAreaSelect这个jQuery插件能够选取一张图片中一个矩形区域。基于Prototype与 ...

【原创】小白学jquery Mobile《构建跨平台APP:jQuery Mobile移动应用实战》连载五(给按钮加图标)

在范例5-4所使用的导航栏中,已经为按钮加入了图标的样式,但是当时并没有介绍按钮的图标究竟是怎么一回事 ...

图片篇-高性能WEB开发

本节的主要内容是:缩小图片大小,高性能WEB开发,合并图片和拆分图片,透明图片处理,多域名下载图片,I ...

最新问答

更多

获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)

我用Google搜索了一个解决方案。 “EnumDisplayModeProvider”是我自己设置网站的各种模式的枚举。 public EnumDisplayModeProvider GetDisplayModeId() { foreach (var mode in DisplayModeProvider.Instance.Modes) if (mode.CanHandleContext(HttpContext)) {

如何通过引用返回对象?(How is returning an object by reference possible?)

这相对简单:在类的构造函数中,您可以分配内存,例如使用new 。 如果你制作一个对象的副本,你不是每次都分配新的内存,而是只复制指向原始内存块的指针,同时递增一个也存储在内存中的引用计数器,使得每个副本都是对象可以访问它。 如果引用计数降至零,则销毁对象将减少引用计数并仅释放分配的内存。 您只需要一个自定义复制构造函数和赋值运算符。 这基本上是共享指针的工作方式。 This is relatively easy: In the class' constructor, you allocate m

矩阵如何存储在内存中?(How are matrices stored in memory?)

正如它在“熵编码”中所说的那样,使用Z字形图案,与RLE一起使用,在许多情况下,RLE已经减小了尺寸。 但是,据我所知,DCT本身并没有给出稀疏矩阵。 但它通常会增强矩阵的熵。 这是compressen变得有损的点:输入矩阵用DCT传输,然后量化量化然后使用霍夫曼编码。 As it says in "Entropy coding" a zig-zag pattern is used, together with RLE which will already reduce size for man

每个请求的Java新会话?(Java New Session For Each Request?)

你是如何进行重定向的? 您是否事先调用了HttpServletResponse.encodeRedirectURL()? 在这里阅读javadoc 您可以使用它像response.sendRedirect(response.encodeRedirectURL(path)); The issue was with the path in the JSESSIONID cookie. I still can't figure out why it was being set to the tomca

css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)

我认为word-break ,如果你想在一个单词中打破行,你可以指定它,这样做可以解决问题: .column { word-break:break-all; } jsFiddle演示。 您可以在此处阅读有关word-break属性的更多信息。 I think word-break, with which you can specify if you want to break line within a word, will do the trick: .column { word-break

无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)

我认为您忘记在分类时间内缩放输入图像,如train_test.prototxt文件的第11行所示。 您可能应该在C ++代码中的某个位置乘以该因子,或者使用Caffe图层来缩放输入(请查看ELTWISE或POWER图层)。 编辑: 在评论中进行了一次对话之后,结果发现在classification.cpp文件中错误地删除了图像均值,而在原始训练/测试管道中没有减去图像均值。 I think you have forgotten to scale the input image during cl

xcode语法颜色编码解释?(xcode syntax color coding explained?)

转到: Xcode => Preferences => Fonts & Colors 您将看到每个语法高亮颜色旁边都有一个简短的解释。 Go to: Xcode => Preferences => Fonts & Colors You'll see that each syntax highlighting colour has a brief explanation next to it.

在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)

你考虑过第三方拼写检查吗? 您可以将在C#中开发的自定义WinForms控件插入访问数据库吗? VB6控件怎么样? 如果你能找到一个使用第三方库进行拼写检查的控件,那可能会有效。 Have you considered a third party spell checker? Can you insert a custom WinForms controls developed in C# into an access database? What about a VB6 control? If

从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)

我有同样的问题,因为我在远程服务器上有两个图像,我需要在每天的预定义时间复制到我的本地服务器,这是我能够提出的代码... try { if(@copy('url/to/source/image.ext', 'local/absolute/path/on/server/' . date("d-m-Y") . ".gif")) { } else { $errors = error_get_last(); throw new Exception($err

从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))

我不确定我完全明白你在说什么。 你能编辑你的帖子并包含你正在做的Subversion命令/操作的特定顺序吗? 最好使用命令行svn客户端,以便容易为其他人重现问题。 如果您只是想获取文件的旧副本(即使该文件不再存在),您可以使用如下命令: svn copy ${repo}/trunk/moduleA/file1@${rev} ${repo}/trunk/moduleB/file1 其中${repo}是您的存储库的URL, ${rev}是您想要的文件的版本。 这将恢复该文件的旧版本,包括最高版本