2012-07-13 19 views
1

我已经添加了一些脚本来我的网站:http://cargocollective.com/btatest移动jQuery的下跌

不过,我很想把它向下移动40像素。

我试图把它包装在一个div中,但无济于事。

这里的脚本:

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


    $(document).ready(function() { 
     $socialDiv = $('.social'); 
     $socialDiv.css({ 
      'background-image': 'url(http://fearthegrizzly.com/productions/theacrobat/web3.jpg)', 
      'background-repeat': 'no-repeat', 
      'background-attachment': 'fixed', 
      'background-size' : '110% 100%', 
      'height' : socialDivHeight + 'px', 
      'margin-left' : '-50%', 
      'margin-right' : '-50%', 

     }); 
    }); 


    $(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> 

任何帮助,将不胜感激。

感谢

迈克尔

+1

你想换什么* *在'div' ?而且你想将页面上的*什么* – 2012-07-13 20:57:23

+1

您想将脚本移动40px?如果你的意思是一些实际的元素,比如'div',你可以做'margin-top:40px'或'position:relative;顶部:40px' – MrOBrian 2012-07-13 20:58:49

回答

1

添加margin-top属性为您的类名称。社会 CSS设置是这样的:

$socialDiv.css({ 
      'background-image': 'url(http://fearthegrizzly.com/productions/theacrobat/web3.jpg)', 
      'background-repeat': 'no-repeat', 
      'background-attachment': 'fixed', 
      'background-size' : '110% 100%', 
      'height' : socialDivHeight + 'px', 
      'margin-left' : '-50%', 
      'margin-right' : '-50%', 
      'margin-top': '40px' 
     }); 
+0

完美!谢谢 – Michael 2012-07-13 21:12:22