Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="wrapper">
  <ul>
    <li>
      <div class="picBox">
        <div class="show">
          <img src="https://jacokwu.cn/images/public/author.jpg" alt="">
        </div>
        <div class="hide">
          <h3>这是一段介绍</h3>
        </div>
      </div>
    </li>
    <li>
      <div class="picBox">
        <div class="show">
          <img src="https://jacokwu.cn/images/public/author.jpg" alt="">
        </div>
        <div class="hide">
          <h3>这是一段介绍</h3>
        </div>
      </div>
    </li>
    <li>
      <div class="picBox">
        <div class="show">
          <img src="https://jacokwu.cn/images/public/author.jpg" alt="">
        </div>
        <div class="hide">
          <h3>这是一段介绍</h3>
        </div>
      </div>
    </li>
    <li>
      <div class="picBox">
        <div class="show">
          <img src="https://jacokwu.cn/images/public/author.jpg" alt="">
        </div>
        <div class="hide">
          <h3>这是一段介绍</h3>
        </div>
      </div>
    </li>
    <li>
      <div class="picBox">
        <div class="show">
          <img src="https://jacokwu.cn/images/public/author.jpg" alt="">
        </div>
        <div class="hide">
          <h3>这是一段介绍</h3>
        </div>
      </div>
    </li>
    <li>
      <div class="picBox">
        <div class="show">
          <img src="https://jacokwu.cn/images/public/author.jpg" alt="">
        </div>
        <div class="hide">
          <h3>这是一段介绍</h3>
        </div>
      </div>
    </li>
    <li>
      <div class="picBox">
        <div class="show">
          <img src="https://jacokwu.cn/images/public/author.jpg" alt="">
        </div>
        <div class="hide">
          <h3>这是一段介绍</h3>
        </div>
      </div>
    </li>
    <li>
      <div class="picBox">
        <div class="show">
          <img src="https://jacokwu.cn/images/public/author.jpg" alt="">
        </div>
        <div class="hide">
          <h3>这是一段介绍</h3>
        </div>
      </div>
    </li>
    <li>
      <div class="picBox">
        <div class="show">
          <img src="https://jacokwu.cn/images/public/author.jpg" alt="">
        </div>
        <div class="hide">
          <h3>这是一段介绍</h3>
        </div>
      </div>
    </li>
    <li>
      <div class="picBox">
        <div class="show">
          <img src="https://jacokwu.cn/images/public/author.jpg" alt="">
        </div>
        <div class="hide">
          <h3>这是一段介绍</h3>
        </div>
      </div>
    </li>
    <li>
      <div class="picBox">
        <div class="show">
          <img src="https://jacokwu.cn/images/public/author.jpg" alt="">
        </div>
        <div class="hide">
          <h3>这是一段介绍</h3>
        </div>
      </div>
    </li>
    <li>
      <div class="picBox">
        <div class="show">
          <img src="https://jacokwu.cn/images/public/author.jpg" alt="">
        </div>
        <div class="hide">
          <h3>这是一段介绍</h3>
        </div>
      </div>
    </li>
  </ul>
</div>
              
            
!

CSS

              
                * {
  margin: 0;
  padding: 0;
  list-style: none;
}
body {
  background-color: #f1e1ff;
}
img {
  width: 180px;
  height: 180px;
}
.wrapper {
  margin: 80px auto;
  width: 900px;
}
.wrapper li {
  position: relative;
  display: inline-block;
  width: 180px;
  height: 180px;
  margin: 5px;
  perspective: 300px;
}
.picBox {
  transform-style: preserve-3d;
  animation: 200ms ease-out 0ms 1 normal forwards;
  transform-origin: 50% 50% -90px;
}
.picBox,
.hide,
.show {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
}
.hide {
  background-color: #000;
  color: #fff;
  line-height: 180px;
  text-align: center;
  transform: translate3d(0, 0, -1px);
}

/*top进入*/
.out-top .hide,
.in-top .hide {
  transform-origin: 0% 100%;
  transform: translate3d(0, -100%, 0) rotate3d(1, 0, 0, 90deg);
}
.in-top .picBox {
  animation-name: in-top;
}
.out-top .picBox {
  animation-name: out-top;
}
@keyframes in-top {
  form {
    transform: rotate3d(0, 0, 0, 0deg);
  }
  to {
    transform: rotate3d(-1, 0, 0, 90deg);
  }
}
@keyframes out-top {
  form {
    transform: rotate3d(-1, 0, 0, 90deg);
  }
  to {
    transform: rotate3d(0, 0, 0, 0deg);
  }
}

/*right进入*/
.out-right .hide,
.in-right .hide {
  transform-origin: 0% 0%;
  transform: translate3d(100%, 0, 0) rotate3d(0, 1, 0, 90deg);
}
.in-right .picBox {
  animation-name: in-right;
}
.out-right .picBox {
  animation-name: out-right;
}
@keyframes in-right {
  form {
    transform: rotate3d(0, 0, 0, 0deg);
  }
  to {
    transform: rotate3d(0, -1, 0, 90deg);
  }
}
@keyframes out-right {
  form {
    transform: rotate3d(0, -1, 0, 90deg);
  }
  to {
    transform: rotate3d(0, 0, 0, 0deg);
  }
}

/*bottom进入*/
.out-bottom .hide,
.in-bottom .hide {
  transform-origin: 0% 0%;
  transform: translate3d(0, 100%, 0) rotate3d(-1, 0, 0, 90deg);
}
.in-bottom .picBox {
  animation-name: in-bottom;
}
.out-bottom .picBox {
  animation-name: out-bottom;
}
@keyframes in-bottom {
  form {
    transform: rotate3d(0, 0, 0, 0deg);
  }
  to {
    transform: rotate3d(1, 0, 0, 90deg);
  }
}
@keyframes out-bottom {
  form {
    transform: rotate3d(1, 0, 0, 90deg);
  }
  to {
    transform: rotate3d(0, 0, 0, 0deg);
  }
}

/*left进入*/
.out-left .hide,
.in-left .hide {
  transform-origin: 100% 0%;
  transform: translate3d(-100%, 0, 0) rotate3d(0, -1, 0, 90deg);
}
.in-left .picBox {
  animation-name: in-left;
}
.out-left .picBox {
  animation-name: out-left;
}
@keyframes in-left {
  form {
    transform: rotate3d(0, 0, 0, 0deg);
  }
  to {
    transform: rotate3d(0, 1, 0, 90deg);
  }
}
@keyframes out-left {
  form {
    transform: rotate3d(0, 1, 0, 90deg);
  }
  to {
    transform: rotate3d(0, 0, 0, 0deg);
  }
}

              
            
!

JS

              
                var oLi = $("li");
var arr = [];
//获取方向->获取进出->添加类名

//初始化
//获取li位置信息,宽高
init();
function init() {
  //将li转换成数组
  Array.prototype.slice.call(oLi, 0).forEach(function(ele, index) {
    arr.push({
      w: ele.offsetWidth,
      h: ele.offsetHeight,
      l: ele.offsetLeft,
      t: ele.offsetTop
    });
    bindEvent(ele, index);
  });
}

function bindEvent(ele, index) {
  $(ele).on("mouseenter", function(e) {
    addClass(e, ele, "in", index);
  });
  $(ele).on("mouseleave", function(e) {
    addClass(e, ele, "out", index);
  });
}

function addClass(e, ele, state, index) {
  //获取进入的方向
  var d = getD(e, index);
  var str = "";
  switch (d) {
    case 0:
      str = "-left";
      break;
    case 1:
      str = "-top";
      break;
    case 2:
      str = "-right";
      break;
    case 3:
      str = "-bottom";
      break;
  }
  ele.className = "";
  ele.classList.add(state + str);
}

function getD(e, index) {
  var w = arr[index].w,
    h = arr[index].h,
    l = arr[index].l,
    t = arr[index].t;
  x = e.pageX - l - w / 2;
  y = e.pageY - t - h / 2;
  //获取进入方向
  d = Math.round((Math.atan2(y, x) * (180 / Math.PI) + 180) / 90) % 4;
  return d;
}

              
            
!
999px

Console