1

私のサイトにスクリプトを追加しました:http://cargocollective.com/btatest

ただし、40px下に移動したいと思います。

私はそれを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次のように、クラス名.socialCSS設定にプロパティを追加します。

$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 に答える