2012-08-01 93 views
0

我好像在页面的右侧有一些过度的水平滚动。全宽问题第2部分

我已经推断它是与我的网站顶部的脚本有关 - 当我删除它时,问题自行解决。

只是想给你一个我希望实现的想法;我想要顶部的图像跨越浏览器的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> 
+0

嘿,现在你可以改变你的代码,如果是的话,请创建一个jsfiddle链接,并把你的HTML和CSS代码....... – 2012-08-01 09:39:04

+0

请把你的代码你试过了吗? – Vins 2012-08-01 09:39:19

+0

耶,jsfiddle会帮助...很难让我看到是什么原因造成的。虽然你可以尝试'html,body {width:100%}' – neokio 2012-08-01 09:41:28

回答

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;赋值给它来使该元素脱离“正常”流程。

+0

对不起,我不确定你的意思。当谈到Jquery时,我正在经历一个小白咒。 – Michael 2012-08-01 10:23:49

+0

@ user1522319我的答案中没有一行jQuery;只是普通的CSS是你的问题... – feeela 2012-08-01 10:56:12

+0

当我向CSS添加一个'.social {position:relative;}'时,仍然存在滚动问题,'绝对'会彻底删除'.social'。 – Michael 2012-08-01 11:14:11