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 8893955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:22:36+00:00 2026-06-14T23:22:36+00:00

I don’t know if it is possible to do this, like I have 2

  • 0

I don’t know if it is possible to do this, like I have 2 js files.
The first Js File:

var news_pos, about_pos, services_pos, clients_pos;

function define_pos() {

    var $top_slides=$('#top_slides'), 
        $mid_nav=$('#mid_nav'), 
        $news_section=$('#section-1');

    var fixed_height = $top_slides.height() + $mid_nav.height();

    news_pos = fixed_height - 20;
    about_pos = fixed_height + $news_section.height();
    services_pos = fixed_height + $news_section.height() * 2;
    clients_pos = fixed_height + $news_section.height() * 3;
}

$(document).ready(function() {

    var section_news = $('#section-1'),
        section_about = $('#section-2'),
        section_services = $('#section-3'),
        section_clients = $('#section-4');

    setheight();

    function setheight() {
        var section_height = $(window).height() + 200;
        $section_news.height(section_height);
        $section_about.height(section_height); 
        $section_services.height(section_height);
        $section_clients.height(section_height);
        define_pos();
    }
});
  1. The second JS File:

    $(document).ready(function() {

    var nav = {
    
        '$btn1': $('#btn1'),
        '$btn2': $('#btn2'),
        '$btn3': $('#btn3'),
        '$btn4': $('#btn4'),
        '$btn5': $('#btn5'), 
    
        myclick : function() {
    
            myclicked(nav.$btn1, 0);
            myclicked(nav.$btn2, news_pos);
            myclicked(nav.$btn3, about_pos);
            myclicked(nav.$btn4, services_pos);
            myclicked(nav.$btn5, clients_pos);
    
            function myclicked(j,k) {
                j.click(function(e) {    
                    e.preventDefault();
                    $('html,body').animate({scrollTop: k}, 1000);
                });
            }
            // Is it right to do return{'myclick':myclick}, 
            // how to call? seems not logical
        }
    };
    
    // Here will not work because it say news_pos is undefined.
    // If I use setTimeout(nav.myclick,1000), it will works but
    // I want to run it right the when position is caculated.
    nav.myclick(); 
    

    });

How do I pass the nav.myclick() function to the frist js file and put it in setheight() and under define_pos()?
By the way writing codes right in stackoverflow is strange,press tab not really give you any spacing.

  • 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-14T23:22:37+00:00Added an answer on June 14, 2026 at 11:22 pm

    Right now, function setheight(){ } is an internal function in the first $(document).ready(function(){}. Its “scope” (visibility) is limited to inside that function.

    To make it visible to everyone, you need to move it outside of $(document).ready(function(){}.

    Then, declare the first file before the second one, and functions in the second file can now use setheight().


    To use myClick:

    Your function now is myclicked() so you need to change that to myclick(). Then, you can call the functions in the global scope:

    function myclick(j,k){            
        j.click(function(e) {   
        e.preventDefault();
        $('html,body').animate({scrollTop: k}, 1000);
        setheight();
        define_pos();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Don't know if anyone can help me with this or if it's even possible.
I don't know how better to describe this. So take this example. var a
Don't know if this has been answered before. Have custom routes to users. If
don't know if this is possible.. I'm using sqlite3 schema: CREATE TABLE docs (id
Don't know why but I can't find a solution to this. I have 3
don't know better title for this, but here's my code. I have class user
I don't know why, but this code worked for me a month ago... maybe
Don't know if I'm missing something here. I'd like to run multiple global variables
Don't know why this doesn't work. I can't do implicit animation for a newly
Don't overthink this - there's a very commonly used term and I ... have

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.