Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9008257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:54:01+00:00 2026-06-16T01:54:01+00:00

I’ve looked up multiple examples in JavaScript. But the result still turns up negetive.

  • 0

I’ve looked up multiple examples in JavaScript. But the result still turns up negetive. Here is the Situation.

I have a website that have a Top Navigation. Depending on the Nav Button pressed, a menu to the left appears on the page with more selections.

Example:
You have Home | Products | Crew | About

User clicks “Products” and it opens up a new page with a Menu on the left showing

Desktops
Laptops
Notebooks
eReaders
Mp3 Players
Tablets
Phones

I want the menu on the left to be approximately 420px from the top when the user is fully scrolled up to the top. As he scrolls down it will scroll to the top. Once it reaches the top of the displayed page, it becomes fixed at the top location.

The Nav Bar on the top is hard-coded into the Master Page. The Menu on the Left is a ContentPlaceHolder in the Master Page and the Content changes based on the page being viewed.

I tried using the JavaScript code:

<script type="text/javascript">
    $(document).on('scroll', function () {
        if ($('#bar')[0].offsetTop < $(document).scrollTop()) {
            $("#bar").css({ position: "fixed", top: 0 });
        }
        if ($(document).scrollTop() < $("#position-saver")[0].offsetTop) {
            $("#bar").css({ position: "static", top: 0 });
        }
    });
</script>

but it doesn’t work. I can’t figure out why. This is the Master Page Code.

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site.Master.cs" Inherits="StasisGamerLounge.Site1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">`
    <meta charset="utf-8" />
    <title>Stasis Gamer Group - <%: Page.Title %></title>
    <asp:PlaceHolder ID="PlaceHolder1" runat="server">     
          <%: Scripts.Render("~/bundles/modernizr") %>
    </asp:PlaceHolder>  
    <webopt:BundleReference ID="BundleReference1" runat="server" Path="~/Content/css" /> 
    <link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
    <meta name="viewport" content="width=device-width" />
    <asp:ContentPlaceHolder runat="server" ID="HeadContent" />
    <script type="text/javascript">
        $(document).on('scroll', function () {
            if ($('#bar')[0].offsetTop < $(document).scrollTop()) {
                $("#bar").css({ position: "fixed", top: 0 });
            }
            if ($(document).scrollTop() < $("#position-saver")[0].offsetTop) {
                $("#bar").css({ position: "static", top: 0 });
            }
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div class="float_right">
        <section id="login">
                    <asp:LoginView ID="LoginView1" runat="server" ViewStateMode="Disabled">
                        <AnonymousTemplate>
                                <a id="registerLink" runat="server" href="~/Account/Register.aspx">Register </a> | 
                                <a id="loginLink" runat="server" href="~/Account/Login.aspx"> Log in</a>
                                <br />
                        </AnonymousTemplate>
                        <LoggedInTemplate>
                        <p>
                            Greetings, <a id="A1" runat="server" class="username" href="~/Account/Manage.aspx" title="Manage your account">
                                <asp:LoginName ID="LoginName1" runat="server" CssClass="username" /></a>!
                            <asp:LoginStatus ID="LoginStatus1" runat="server" LogoutAction="Redirect" LogoutText="Log off" LogoutPageUrl="~/" />
                        </p>
                    </LoggedInTemplate>
                </asp:LoginView>
            </section>
        </div>
    <div class="bodywrapper">
        <div class="logo">
        </div>
        <div class="header">
        </div>
        <div class="topnav">
            <ul id="navbar">
                <li><asp:HyperLink runat="server" ID="home" NavigateUrl="~/Default.aspx">Home</asp:HyperLink></li>
                <li><asp:HyperLink runat="server" ID="games" NavigateUrl="~/Games.aspx">Games</asp:HyperLink></li>
               <% if (Page.User.Identity.IsAuthenticated ) { %> <li><asp:HyperLink runat="server" ID="myFiles" NavigateUrl="~/Drive.aspx">My Files</asp:HyperLink></li>
                <li><asp:HyperLink runat="server" ID="events" NavigateUrl="~/Events.aspx">Events</asp:HyperLink></li> <% } %>
                <li><asp:HyperLink runat="server" ID="about" NavigateUrl="~/About.aspx">About</asp:HyperLink></li>                    
            </ul>
        </div>
        <div class="contentwrapper">
        <div class="leftMenu" id="bar">
            <h3>Menu</h3>
            <asp:ContentPlaceHolder ID="MenuContent" runat="server">

            </asp:ContentPlaceHolder>
        </div>`

Am I putting the Javascript in wrong, or what’s going on here? Is there a different way to accomplish this in ASP.Net?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T01:54:02+00:00Added an answer on June 16, 2026 at 1:54 am

    Here’s a basic, generic implementation: http://jsfiddle.net/SwHqk/

    I noticed you are using jQuery, so I went with that for simplicity.

    $(window).scroll(function(e){
        var top = $(window).scrollTop();
    
        if (top > 200) // this would be the "normal" position of the menu
            $("#floating-box").addClass("fixed");
        else
            $("#floating-box").removeClass("fixed");
    });​
    

    CSS (distilled to the important bits)

    #floating-box{
        margin-top:200px;
        position:absolute;
        margin-left:5px;
    }
    #floating-box.fixed{
        position:fixed;
        top:0;
        margin-top:5px; /* you could use top instead of margin-top for both stationary/fixed */
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I used javascript for loading a picture on my website depending on which small
This could be a duplicate question, but I have no idea what search terms
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.