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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:36:33+00:00 2026-06-01T10:36:33+00:00

I just saw something very interesting in vk.com Basically in profile page the right

  • 0

I just saw something very interesting in vk.com

Basically in profile page the right column is changing its width when the left column is gone of the view.

Example : http://vk.com/durov

Just scroll down a little bit to see it.

  • 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-01T10:36:34+00:00Added an answer on June 1, 2026 at 10:36 am

    Every element in the DOM defines certain spatial offset properties that can be accessed from JavaScript, them being offsetTop, offsetLeft etc. which give you the value how much offset it has from its parent. You can also access the parent in question with a while loop which simply assigns the next parent until none are left ( you can add their offsets to the variables of the original offset to gain the “true” (x,y) offset) and the while loop exists when there are no more parent elements.

    Then you do some simple logic to check whether or not it is located within the viewport (hint – use the page offset and width/height properties of the window object). Is this enough to go on or do you need a code sample?

    You could do some hacks if you know where exactly your element will appear and its height (width is really of no consequence here), but that’s a brute force approach. Simply checking the page Y offset and height against the predetermined “maxY” of the element you’re trying to get offscreen to display a certain div to the right (like in the example given).

    ADDENDUM: (Even more to the point)

    This checks whether ANY part of the element is visible in the viewport:

    function isVisibleInViewport(elem)
    {
        var y = elem.offsetTop;
        var height = elem.offsetHeight;
    
        while ( elem = elem.offsetParent )
            y += elem.offsetTop;
    
        var maxHeight = y + height;
        var isVisible = ( y < ( window.pageYOffset + window.innerHeight ) ) && ( maxHeight >= window.pageYOffset );
        return isVisible; 
    
    }
    

    I tried writing it with clarity in mind. You can shorten it further if you wish. Even expand it to include logic if you wish to move to the side (x-axis, offsetLeft variable). And changes to your logic ought to be minimal if you want to check whether it’s completely within view ( can’t see a reason though).

    My example usage

    The logic to govern when to call this function goes beyond the scope of this, I hope you have some method in mind. My example:

    function check()
    {
        var canvas = document.getElementById("webGlExperiments");
        if(isVisibleInViewport(canvas))
            document.getElementById("test").innerHTML = "It is!";
        else
            document.getElementById("test").innerHTML = "It is not!";
    }
    

    And then add an event listener to check for scrolls:

    window.addEventListener("scroll", check, false);
    

    For my example, you’ll also need another element like a canvas with the id webGlExperiments, change it to something that suits you and your problem. This is the div in question I used in my test which you can adapt for yourself:

    <div id="test" style="margin-top:100px;">Testing, testing!</div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I just saw a weird behavior In one script there is something like:
I've just learned a bit of CodeIgniter Framework and I saw something which I
Just saw a view in iOS settings page, wondering how to create it, it
I just saw this cool feature of JQuery which is JQuery Portlet http://jqueryui.com/demos/sortable/portlets.html I
I've just saw a very slow query in my application. Table 'News' has more
I've encountered something very strange, and things just don't add up. First of all,
I just saw something unusual behavior in Google Chrome's inbuilt spell check feature. This
I have used PHP for a long time, but I just saw something like,
I just saw this question and it reminds me of something I usually do
I just saw something like this in a C++ code (that compiles and probably

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.