제이쿼리 자동 슬라이드 구현
자동슬라이드 구현
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>
</body>
</html>
CSS
@charset "UTF-8";
li {
font-size: 30px;
border: 1px solid #000;
list-style: none;
display: inline-block;
padding: 4px 20px;
}
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
setInterval(fnSlide, 3000);
function fnSlide() {
$("ul").animate({ "margin-left": "-100px" }, 1200, function () {
$("ul").css({ "margin-left": "-8px" });
$("li:first-child").insertAfter("li:last-child");
});
};
Leave a comment