javascript - 如何通过jquery或CSS放大和缩小循环动画中的元素

标签 javascript jquery html css

我有一个图像将在动画循环中上下移动,它的阴影元素将相应地缩小和放大。这将产生一种效果,就像物体悬浮在空气中一样。我在以下链接中附上了引用图片 -

http://s28.postimg.org/k3mioxzel/sample_image.jpg

我使用以下代码通过 jQuery 使图像上下移动并且工作正常。

$(document).ready(function () {  
  $('#myImg').load(function(){    
      setInterval(function(){
        $('#myImg').animate({'marginTop':"-=35px"},"slow");            
        $('#myImg').animate({'marginTop':"+=35px"},"slow");
        },1000/30);   
  });
});

但是我不能随着图像的移动来放大或缩小阴影元素。我在 CSS 代码中创建了 shadow 元素。请帮助我。

#oval {
    width: 226px;
    height: 50px;
    background: #d8b54c;
    top: 50%;
    left: 50%;
    position: absolute;
    margin-top: 150px;
    margin-left: -113px;
    -moz-border-radius: 226px / 50px;
    -webkit-border-radius: 226px / 50px;
    border-radius: 226px / 50px; }

最佳答案

这将达到目的,将 width/height/marginTopmarginBottom 增量/减量修改为需要:(Working Example)

$(document).ready(function () {  
  $('#myImg').load(function(){    
      setInterval(function(){
        $('#myImg').animate({'marginTop':"-=35px"},"slow");            
        $('#myImg').animate({'marginTop':"+=35px"},"slow");
        },1000/30);  
      setInterval(function(){
        $('#oval').animate({'width': "-=10px",'height': "-=10px",
                            'marginTop': "+=5px", 'marginLeft': "+=5px" 
         }, "slow");
        $('#oval').animate({'width': "+=10px", 'height': "+=10px",
                            'marginLeft': "-=5px",'marginTop': "-=5px"
                           }, "slow");
      }, 1000 / 30);
});

关于javascript - 如何通过jquery或CSS放大和缩小循环动画中的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22762706/

相关文章:

html - 调整页面大小时, float div 会下降

html - 为什么 id 不覆盖 bootstrap 中的类?

javascript - 无法在 'querySelector' : 'Document' is not a valid selector 上执行 '#traveller[36350015][date_of_birth(3i)]'

javascript - 使用 <script src=.... 的跨框架脚本来查找站点的状态代码 - 安全问题?

javascript - 为什么我的点击没有按预期工作?

javascript - 如何构建自定义 jquery ui 文件

javascript - 当 var trees = new Array ("redwood", "bay", "cedar"时 0 如何成为树的属性)

javascript - 如何将 JSON 中的嵌套数组拆分为 Google 表格中的表格(使用 Javascript?)

javascript - 使用鼠标滚轮和侧边栏更改 Div Y 位置

javascript - jquery 加载函数在 chrome 中不起作用,而在 firefox 中起作用?