반응형

# 스크롤 바 하단으로 위치하기(제이쿼리)

  • 채팅 기능 작업 시 overflow: scroll; 로 스크롤이 추가되도록 진행
  • 문제점은 채팅이 추가될 경우 스크롤이 생성은 되지만, 스크롤이 상단에 고정.
  • 구글링을 통해 제이쿼리를 이용한 스크롤 하단 고정 방법 확인.
$('#입력한 id값').scrollTop($('#입력한 id값')[0].scrollHeight);
<h1 class="mypage-h">채팅</h1>

<div class="chat-view con" id="chatContent">
	...
    	...
       		...
</div>


<script>
		<!-- 채팅 스크롤 하단으로 보내기 -->
	$('#chatContent').scrollTop($('#chatContent')[0].scrollHeight);
	
</script>
  • 해당 코드의 경우 스크롤이 생기도록 한 채팅창의 높이값을 바탕으로 스크롤이 고정되기 때문에 제이쿼리를 밑에 삽입해야 기능이 작동한다.

해당 제이쿼리를 상단에 위치 시켰을 경우 발생하는 에러
제이쿼리를 적용한 채팅방 예시

반응형
반응형

# 모달윈도우(팝업효과)

## 결과물

See the Pen 모달윈도 by dlagusgh1 (@dlagusgh1) on CodePen.

## html

<input type="checkbox" id="popup" />
<label for="popup">view</label>
<div>
  <div>
    <label for="popup"></label>
    안녕하세요.
  </div>
  <label for="popup">
  </label>
</div>

## CSS

input[id*="popup"] {
  display: none;
}
input[id*="popup"] + label {
  display: inline-block;
  padding: 20px;
  background: #ffcd41;
  color: #fff;
}
input[id*="popup"] + label + div {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 100;
}
input[id*="popup"] + label + div > div {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 500px;
  height: 300px;
  background: #fff;
  z-index: 2;
}
input[id*="popup"] + label + div > div > label {
  position: absolute;
  top: 0%;
  right: 0%;
  transform: translate(40%, -40%);
  padding: 20px;
  background: #dd5347;
  border-radius: 100%;
  z-index: 1;
}
input[id*="popup"] + label + div > label {
  position: absolute;
  top: 0%;
  left: 0%;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.9);
  z-index: 1;
}
input[id*="popup"] + label + div {
  opacity: 0;
  visibility: hidden;
  transition: all 1s;
}
input[id*="popup"]:checked + label + div {
  opacity: 1;
  visibility: visible;
}

## 출처

https://www.youtube.com/watch?v=h79yJiTenEo

https://pixabay.com/ko/

반응형
반응형

# 움직이는 이미지 효과

## 결과물

See the Pen 움직이는 이미지 by dlagusgh1 (@dlagusgh1) on CodePen.

## html

<div class="logo">
  <img src="https://cdn.pixabay.com/photo/2018/07/28/00/15/horse-3567041_960_720.jpg" alt="logo" class="logo">
</div>

## CSS

.logo > img {
  width: 300px;
  height: 300px;
  animation: watch 1s linear infinite both;
}

/* 탑바 로고 움직임 */
@keyframes watch {
  0% {
    transform: translate(0);
  }
  20% {
    transform: translate(-5px, 5px);
  }
  40% {
    transform: translate(-5px, -5px);
  }
  60% {
    transform: translate(5px, 5px);
  }
  80% {
    transform: translate(5px, -5px);
  }
  100% {
    transform: translate(0);
  }
}
.logo > img:hover {
  animation-play-state: paused;
}

## 출처

https://www.youtube.com/watch?v=AKgkKv0qKgw

https://pixabay.com/ko/

반응형
반응형

# 이미지 슬라이드 효과

## 결과물

See the Pen 이미지 슬라이드 by dlagusgh1 (@dlagusgh1) on CodePen.

## html

<div class="slide-box con flex">
  <div class="slide-image flex-ai-c">
    <img src="https://cdn.pixabay.com/photo/2020/05/15/11/49/pet-5173354_960_720.jpg" id=mainImage alt="slide" />
  </div>
</div>

## CSS

.slide-box {
  width: 100%;
  height: 500px;
  overflow: hidden;
  margin-top: 30px;
}

.slide-box > slide-image > img {
  max-width: 100%;
  width: 100%;
  height: auto;
  display: inline-block;
}

## 제이쿼리

var myImage = document.getElementById("mainImage");
var imageArray = [
  "https://cdn.pixabay.com/photo/2020/05/15/11/49/pet-5173354_960_720.jpg",
  "https://cdn.pixabay.com/photo/2020/06/06/09/36/armored-car-5265887_960_720.jpg",
  "https://cdn.pixabay.com/photo/2020/05/24/16/14/switzerland-5214914_960_720.jpg"
];
var imageIndex = 0;

function changeImage() {
  myImage.setAttribute("src", imageArray[imageIndex]);
  imageIndex++;
  if (imageIndex >= imageArray.length) {
    imageIndex = 0;
  }
}
setInterval(changeImage, 2000);

## 출처

https://pixabay.com/ko/

반응형

+ Recent posts