首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >根据其他图像的位置将图像旋转90度

问根据其他图像的位置将图像旋转90度
EN

Stack Overflow用户
提问于 2014-07-12 20:13:52
回答 1查看 998关注 0票数 3

我正在尝试创建一个水平视差网站。我有一张id为#ellipse的图片,它从右到左滑动到不同的位置,比如说-

代码语言:javascript
复制
item.screenPos=["320%","220%","120%","34%","-80%","-180%","-280%","-380%"];

当此图像达到34%的位置时,它将在屏幕上可见。

我想要另一个具有id #strip的图像(它不滑动,固定在屏幕的中心),当上面的图像(具有id #ellipse)达到34%的位置时旋转90度。

我现在用的是这个-

代码语言:javascript
复制
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>   
$(document).ready(function(){
  $("#ellipse").position("34%")(function(){
    $("#strip").rotate({angle:90});
  });
}); 
</script>

有人能帮我吗。我是开放的使用javascript,jquery,css和php。

EN

回答 1

Stack Overflow用户

发布于 2014-07-19 00:54:40

您需要使用视差的库,或者定义随着视差动画的推进而触发的事件。例如,假设您的视差动画将由滚动位置控制:

代码语言:javascript
复制
// catch the event that triggers the animation
// this could be a mouse position, a accelerometer angle, etc
$(window).scroll(function(){
    var currentScrollPosition = $(document).scrollTop(),
    // lets say your scroll animation should happen in the first 
    // 300px of scroll, therefore 0px = first frame of anim
    // 300px = last frame of anim
        animationPercentage = currentScrollPosition/300; // 0 to 1

    // only animate if in range
    if (animationPercentage <= 1){
        // now you can control stuff based on the percentage of the animation

        //                position = start pos + delta * %
        $('#ellipse').css('left', (-380 +  (320 + 380) * animationPercentage );

        // rotate as a function of animationPercentage
        // let's say that #ellipse is visible at 50% of the animation
        if (animationPercentage >= 0.5){
            $('#strip').css('-webkit-transform', 'rotate(90deg)');  // or
            $('#strip').addClass('rotate');
        }
    }
});

现在,如果位置与动画事件不成比例,则可以执行以下操作:

代码语言:javascript
复制
item.screenPos={
    "0.9":"320%", // position at 90% of animation
    "0.85":"220%", // position at 85% of animation
    "0.71":"120%", //... you get the point
    "0.5":"34%",
    "0.48":"-80%",
    "0.2":"-180%",
    "0.15":"-280%",
    "0":"-380%"
};

并将animationPercentage与每个值的键进行匹配。但我相信你可以自己试一试。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24712826

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档