代码之家  ›  专栏  ›  技术社区  ›  Jake

使用CSS使放大镜遵循椭圆形路径

  •  4
  • Jake  · 技术社区  · 10 年前

    在下面的提琴中,我想让放大镜顺时针方向沿着椭圆的路径(穿过黑色轮廓)。如何操纵属性以实现此目的?

    .oval{
      background:url(http://s8.postimg.org/wozw0oq9x/oval.png);
      width:743px;
      height:305px;
      margin-top:20px;
      margin-left:20px;
    }
    
    .glass {
    	display:block;
        background: url(http://s29.postimg.org/5i2f94m83/magnifying_glass.png);
    	width:100px;
    	height:83px;
      left: 487px;
        top: -198px;
      
        position: relative;
    
        -webkit-animation: myOrbit 4s linear infinite; /* Chrome, Safari 5 */
           -moz-animation: myOrbit 4s linear infinite; /* Firefox 5-15 */
             -o-animation: myOrbit 4s linear infinite; /* Opera 12+ */
                animation: myOrbit 4s linear infinite; /* Chrome, Firefox 16+, 
                                                          IE 10+, Safari 5 */   
    }
    
    @keyframes myOrbit {
        0%  { transform: rotate(0deg) translateX(5px) translateY(120px) rotate(0deg) scale(1); }
        25%  { transform: rotate(90deg) translateX(5px) translateY(120px) rotate(-90deg) scale(.75); }
        50%  { transform: rotate(180deg) translateX(5px) translateY(120px) rotate(-180deg) scale(.60); }
        75%  { transform: rotate(270deg) translateX(5px) translateY(120px) rotate(-270deg) scale(.75); }
        100%  { transform: rotate(360deg) translateX(5px) translateY(120px) rotate(-360deg) scale(1); }
    }
    <div class="oval">
    </div>
    
    <div class="glass">
    </div>

    https://jsfiddle.net/szq4336q/2/

    1 回复  |  直到 10 年前
        1
  •  2
  •   A.J. Uppal    10 年前

    尝试以下操作:

    .deform  {
        width: 200px;
        height: 200px;
        -webkit-transform: scaleX(3);
        background-color: lightblue;
        left: 270px;
        position: absolute;
        top: 50px;
        border-radius: 50%;
    }
    
    .rotate {
        width: 100%;
        height: 100%;
        -webkit-animation: circle 10s infinite linear;    
        -webkit-transform-origin: 50% 50%;
    }
    
    .counterrotate {
        width: 50px;
        height: 50px;
        -webkit-animation: ccircle 10s infinite linear;    
    }
        
    .inner {
        width:100px;
    	height:83px;
        position: absolute;
        left: -20px;
        top: 0px;
        background: url(http://s29.postimg.org/5i2f94m83/magnifying_glass.png);
        display: block;
        -webkit-transform: scaleX(0.33);
    }
    
    @-webkit-keyframes circle {
        from {-webkit-transform: rotateZ(0deg)}
        to {-webkit-transform: rotateZ(360deg)}
    }
    
    @-webkit-keyframes ccircle {
        from {-webkit-transform: rotateZ(360deg)}
        to {-webkit-transform: rotateZ(0deg)}
    }
    <div class="deform">
    <div class="rotate">
    <div class="counterrotate">
    <div class="inner">
    </div>
    </div>
    </div>
    </div>