일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 를
- 안짤렸다
- 클래스 토글
- ROUTER 버전6
- chart.js
- react-router
- 2020
- 언젠간가겠지
- classList add
- 리엑트할수있는퍼블리셔라규
- classList
- 방심은금물
- 접근성
- classList remove
- 간식금지다!
- 대표님물리기없기
- resize
- 냥빨이다가온다
- 커스텀훅
- windowwidth
- classList toggle
- className
- chart responsive
- react-router-dom
- 내배위의고양이
- 퍼블리싱
- react
- 포트폴리오
Archives
- Today
- Total
틈
[jQuery] 무한 롤링 본문
데이터 바인딩을 포함한, 무한 롤링 예제
데이터 준비하기
var peopleData = [
{
id: 0,
title: "1",
img: "/assets/images/main/image2.png",
href: "123",
},
{
id: 1,
title: "1",
img: "/assets/images/main/image1.png",
href: null,
},
{
id: 2,
title: "2",
img: "/assets/images/main/image2.png",
href: null,
},
{
id: 3,
title: "3",
img: "/assets/images/main/image3.png",
href: null,
},
{
id: 4,
title: "4",
img: "/assets/images/main/image1.png",
href: null,
},
{
id: 5,
title: "1",
img: "/assets/images/main/image2.png",
href: null,
},
{
id: 6,
title: "2",
img: "/assets/images/main/image3.png",
href: null,
},
{
id: 7,
title: "3",
img: "/assets/images/main/image1.png",
href: null,
},
{
id: 8,
title: "4",
img: "/assets/images/main/image2.png",
href: null,
},
{
id: 9,
title: "1",
img: "/assets/images/main/image3.png",
href: null,
},
{
id: 10,
title: "2",
img: "/assets/images/main/image1.png",
href: null,
},
];
jQuery
var $rollingScroll = $(".leftScroll");
var $scrollItem = $rollingScroll.find(".scrollItem");
var rowCount = 0;
var count = 1;
var Length = Data.length;
for (var i = 0; i < Length; i++) {
var $rowItem = $('<div class="Row"></div>');
for (var j = 0; j < 2; j++) {
var index = rowCount < Length ? rowCount : rowCount % Length;
var elem = Data.find(function (x) {
return x.id === index;
});
var $item = $('<div class="Item"></div>'),
$anchorItem = $('<a class="Item"></a>');
if (!elem.href) {
$item.text(elem.title);
$item.css("backgroundImage", "url(" + elem.img + ")");
$rowItem.append($item);
} else {
$anchorItem.attr("href", elem.href);
$anchorItem.text(elem.title);
$anchorItem.css("backgroundImage", "url(" + elem.img + ")");
$rowItem.append($anchorItem);
}
rowCount++;
count += 1;
if (count > 2) {
$scrollItem.append($rowItem);
count = 1;
}
}
}
$scrollItem.clone().addClass("cloneItem").appendTo($rollingScroll);
$scrollItem.css("left", 0);
$rollingScroll.find(".cloneItem").css("left", $scrollItem.width() + "px");
html
<div class="leftScrollWrap">
<div class="leftScroll">
<div class="scrollItem"></div>
</div>
</div>
css
.leftScrollWrap {
height: 600px;
.leftScroll {
.scrollItem {
display: flex;
flex-flow: row nowrap;
align-items: center;
position: absolute;
width: auto;
.Row {
display: inline-flex;
flex-direction: column;
gap: 1.5rem;
.Item {
display: inline-block;
width: 360px;
height: 262px;
margin: 15px;
border-radius: 1.5rem;
background-color: #000;
@include bgInclude(cover);
font-size: 0;
line-height: 0;
}
}
&:not(.cloneItem) {
animation: 70s linear 0s infinite normal forwards running rollingleft1;
}
&.cloneItem {
animation: 70s linear 0s infinite normal none running rollingleft2;
}
}
}
}
'code > Javascript' 카테고리의 다른 글
[jQuery] 첨부파일 input[type=file] 처리 (0) | 2022.07.13 |
---|---|
[jQuery] text 복사 기능 (0) | 2022.07.12 |
[JS] index 값이 length를 넘어설 때, 0 만들기 (0) | 2022.05.17 |
[JS] 숫자 처리 시 2자리를 맞춰야 할 때 (0) | 2022.05.17 |
[JS] audio 관련 event (0) | 2022.05.17 |
Comments