0

我的页面右侧似乎有一些过度的水平滚动。

我推断这与我网站顶部的脚本有关——当我删除它时,问题就会自行解决。

只是为了让您了解我希望实现的目标;我希望顶部的图像跨越浏览器的 100% 宽度,但保持类型居中。

当您第一次访问该站点时,您会很好地了解我在说什么。

http://cargocollective.com/btatest

提前致谢

迈克尔

编辑

代码如下:

<script type="text/javascript">
        // The social div 
    var $socialDiv,
        // The social div's height 
        socialDivHeight = 560,
        currentSocialDivHeight = socialDivHeight;


    $(document).ready(function() {
        $socialDiv = $('.social');
        $socialDiv.css({
            'background-image': 'url(http://a3.sphotos.ak.fbcdn.net/hphotos-ak-prn1/563655_324264884301748_471368753_n.jpg)',
            'background-repeat': 'no-repeat',
            'background-attachment': 'fixed',
           'background-size' : '110% auto',
            'height' : socialDivHeight + 'px',
            'margin-left' : '-100%',
            'margin-right' : '-100%',


        });
    });


    $(window).scroll(function() { 
        //Get scroll position of window 
        var windowScroll = $(this).scrollTop(); 

        var newSocialDivHeight = Math.max(0, socialDivHeight - windowScroll);

        if (Math.abs(newSocialDivHeight - currentSocialDivHeight) < 1)
            return;

        $socialDiv.css({
            'opacity' : 1 - windowScroll / 400
        });

        currentSocialDivHeight = newSocialDivHeight;
    });
</script>
4

1 回答 1

0

<div class="social" style="background-image: …;">导致滚动条。

您正在有效地创建一个 2160 像素宽(包括边距)的元素,并且想知道为什么您有一个水平滚动条?

你有:

.project_content { width: 720px; }
.social {
    /* implied with = 100%, since this is a block element */
    margin-left: -100%; /* add 720px on the left */
    margin-right: -100%; /* add 720px on the right */
}

但是您的目标是使.social宽度为 100%。为了实现这一点,您可以重新排序您的 HTML 结构或通过分配position: relative;或将元素从“正常”流中取出position: absolute;

于 2012-08-01T09:59:45.237 回答