繁体   English   中英

全页滚动和旋转徽标

[英]Full page scroll with rotating logo

我有一个使用Fullpage.js的网站,当我滚动浏览每个部分时,我需要徽标旋转180度。

我怎样才能做到这一点

这是链接: http : //www.bfgstudio.co.uk/testing/VIM/

您应该使用onLeave回调,或者如果愿意,可以使用afterLoad回调。

这样,当您从一张幻灯片移动到另一张幻灯片时,您可以触发一些东西。

jQuery的:

$.fn.fullpage({
    afterLoad: function (anchor, index) {
        $('#cog').toggleClass('active');
    }
});


CSS

#cog {
    background: white;
    border-radius: 10px;
    width: 40px;
    height: 40px;
    position: fixed;
    top: 20px;
    left: 20px;
}
#cog.active {
    transform: rotate(180deg);
    -webkit-transform: rotate(180deg);
    -moz-transform: rotate(180deg);
    -webkit-transition: all 0.3s ease-out;
    -moz-transition: all 0.3s ease-out;
    -o-transition: all 0.3s ease-out;
    transition: all 0.3s ease-out;
}

现场例子

有很多答案,你应该谷歌:

范例:

var $cog = $('#cog'),
$body = $(document.body),
bodyHeight = $body.height();

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

http://jsfiddle.net/kDSqB/

$(function() {
  var rotation = 0, 
    scrollLoc = $(document).scrollTop();
  $(window).scroll(function() {
    var newLoc = $(document).scrollTop();
    var diff = scrollLoc - newLoc;
    rotation += diff, scrollLoc = newLoc;
    var rotationStr = "rotate(" + rotation + "deg)";
    $(".gear").css({
      "-webkit-transform": rotationStr,
      "-moz-transform": rotationStr,
      "transform": rotationStr
    });
  });
})

http://jsfiddle.net/g3k6h/5/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM