클릭시 슬라이드 구현



See the Pen 클릭시 슬라이드 by yoonbitnara (@yoonbitnara) on CodePen.




상세코드

HTML

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>제이쿼리 슬라이드</title>
</head>

<body>
  <div id="insAfter">
    <ul>
      <li>1번</li>
      <li>2번</li>
      <li>3번</li>
    </ul>
  </div>
  <button type="button">클릭하면 이동</button>
</body>

</html>



CSS

@charset "UTF-8";

li {
  font-size: 30px;
  border: 1px solid #000;
  list-style: none;
  display: inline-block;
  padding: 4px 20px;
}

button {
  font-size: 30px;
  cursor: pointer;
}

div#insAfter {
  border: 3px solid #08f;
  margin: 20px 160px;
  width: 88px;
  padding: 4px;
  overflow: hidden;
}

div > ul {
  width: 300px;
  padding: 0;
  border: 3px solid #f30;
  margin: 0;
  position: relative;
}



jQuery

$(function () {
  $("button").click(function () {
    $("ul").animate({ "margin-left": "-100px" }, 3000, function () {
      $("li:first-child").insertAfter("li:last-child");
      $("ul").css({ "margin-left": "-8px" });
    });
  });
});

Leave a comment