0

Following up on this post, I made a test, but I still got a bit of problem - the page has two scroll bars when you click to display the image.

I don't need the background scrollbar when the image is being displayed, I only need the scrollbar on the image container.

How can I hide the background scrollbar without making the page jumpy?

the css,

#container-image {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow-x: auto;
    overflow-y: scroll;
    z-index:100;
}

the html,

<p>Please scroll down until you see the click button</p>
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
<a href="#" class="get-photo">click</a>
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>

<div id="container-image" style="display:none">
    <ul id="items-image">
        <li><img src="winnie-the-pooh-2011-4.jpg"/></li>
    </ul>
</div>

the jquery,

$(document).ready(function(){
        $('.get-photo').click(function(){

            var object = $(this);
            var object_path = object.attr('href');
            var scroll_top = $(window).scrollTop();
            //alert(object_path);
            $('#container-image').show();
            return false;
        });

    });

Here is the test page.

EDIT:

Just managed to hide the body scrollbar and it works on all browsers accept IE8 - how can I fix IE??

$(document).ready(function(){
        $('.get-photo').click(function(){
            $('body').css('overflow', 'hidden');
            var object = $(this);
            var object_path = object.attr('href');
            var scroll_top = $(window).scrollTop();
            var height_document = $(document).height();
            //alert(object_path);

            $('#background-photo').css({

                height:height_document + 'px',
                display:'block'

            });

            $('#container-image').show();
            return false;
        });

        $('#items-image img').click(function(){

            var object = $(this);
            $('body').css('overflow', 'auto');
            $('#container-image').hide();
            $('#background-photo').hide();
            return false;
        });

    });

EDIT:

Fixed IE8:

$('body,html').css('overflow', 'hidden');
Community
  • 1
  • 1
Run
  • 54,938
  • 169
  • 450
  • 748
  • Your sample page has [193 validation errors](http://validator.w3.org/check?uri=http%3A%2F%2Flauthiamkok.net%2Fdump%2Fposition.fixed%2F&charset=%28detect+automatically%29&doctype=Inline&group=0). Take care of those and your chances of cross-browser consistency increases. Also consider using margins or other CSS positioning instead of a million `
    `'s.
    – Sparky Sep 04 '11 at 14:24

2 Answers2

2

Set overflow: hidden on the body while the image is being displayed, to hide the scrollbars:

$('body').css('overflow', 'hidden');
Arnaud Le Blanc
  • 98,321
  • 23
  • 206
  • 194
  • Just managed to hide the body scrollbar and it works on all browsers accept IE8 - how can I fix IE? Thanks! – Run Sep 04 '11 at 14:17
1

I just removed in Firebug following styles:

overflow-x: auto;
overflow-y: scroll;

and I can see the background without scroll. Try it.

But in this case if the background image bigger than visible browser window - you never will be able to see the whole image because of position:fixed

Samich
  • 29,157
  • 6
  • 68
  • 77