1

我在我的网站上添加了一些脚本:http: //cargocollective.com/btatest

但是,我很想将其向下移动 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>

任何帮助,将不胜感激。

谢谢

迈克尔

4

1 回答 1

1

margin-top属性添加到您的 Class Name .social 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'
        });
于 2012-07-13T21:02:44.160 回答