첨부파일이 1개 일 경우 view 에서 이미지 width:100%
첨부 파일이 2개 이상일 경우 width:50% 이렇게 하고 싶은데 어떻게 해야할까요??
|
답변 2개 / 댓글 2개
채택된 답변
+20 포인트
2024-09-03 (화) 12:26:26
view.skin.php 하단에 아래 스크립트를 넣어주세요. 그누순정 기준입니다.
Copy
<script>
images = document.querySelectorAll("#bo_v_img img");
if (typeof images[1] == "object") for (i of images) i.style.width = "50%";
else images[0].style.width = "100%";
</script>
답변에 대한 댓글 1개
2024-09-03 (화) 18:45:32
RYANRYAN
2024-09-03 (화) 08:45:18
Copy
<script>
const galleryImages = document.querySelectorAll('.gallery-image'); //본인 코드에 맞춰 변경
galleryImages.forEach((image) => {
// 첨부 파일 개수
const fileCount = image.querySelectorAll('.file-item').length; //본인 코드에 맞춰 변경
if (fileCount === 1) {
image.style.width = '100%';
} else if (fileCount > 1) {
image.style.width = '50%';
}
});
</script>
답변에 대한 댓글 1개
2024-09-03 (화) 18:45:20
답변 정말 감사합니다.
지식이 없어 코드를 수정할 수 없어서.. 어쩔 수 없었습니다 ㅠㅠ
지식이 없어 코드를 수정할 수 없어서.. 어쩔 수 없었습니다 ㅠㅠ
답변을 작성하려면 로그인이 필요합니다.
큰 도움이 되었어요.