How to rotate image when scrolling using CSS transform?

后端 未结 5 1150
忘掉有多难
忘掉有多难 2021-01-01 06:01

I\'m not sure how to use using jQuery, but has a CSS3 property: transform: rotate

it could be used along with jQuery?

transform:rotate;
-ms-transform         


        
5条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-01 06:55

    Try this fiddle:

    http://jsfiddle.net/kDSqB/

    It's not 100% accurate in working out full rotation, but I think that night be the fiddle environment.

    The code here:

    var $cog = $('#cog'),
    $body = $(document.body),
    bodyHeight = $body.height();
    
    $(window).scroll(function () {
        $cog.css({
            'transform': 'rotate(' + ($body.scrollTop() / bodyHeight * 360) + 'deg)'
        });
    });
    

提交回复
热议问题