vscode
- html이 갑자기 인식 안됨
: 기본설정 > setting > files : associations 확인- 확인결과 .html 이 js로 되어 있어서 인식이 안됨
- js코드의 경우 index와 연결되므로 단독 실행 시 document 정의가 안되어있다고 뜸.
- 실제로 index.html 실행하면 정상 작동함
로그 확인은 chrome 개발자 도구 열어서 log 확인- js코드 미작동 : html header부에 script 코드 미삭제
</section>
<script src="js/main.js"></script>
</body>
</html>
const heart = document.querySelector('.heart_btn'); //하트요소
heart.addEventListener('click', function () {
heart.classList.toggle('on'); //하트 누르면 on 클래스 추가
})
.heart_btn.on .sprite_heart_icon_outline{/*on 클래스 추가 시 이미지 변경*/
background: url('../imgs/background01.png') no-repeat -26px -261px;
}
#header.on {
position: fixed;
}
#header .inner{/*inner 내 컨텐츠를 넣으면 안에 값이 들어옴*/
width: 975px;
height: 77px;/*높이 값은 header내의 자식들에게 줌*/
margin: 0 auto; /*가운데 정렬*/
display: flex;/*가로 배치*/
justify-content: space-between;/*x축 정렬:공간 자동 분배*/
align-items: center;/*y축 정렬*/
transition: all 1s;/*자연스러운효과*/
}
#header.on .inner{
height: 52px;
}
#header .inner .logo .sprite_insta_icon:after{
content: '';/*공백을 받아옴*/
width: 1px;
height: 28px;
background: #000;
position: absolute; /*부모 기준으로 위치 잡음*/
right: -15px;
top: -4px;
transition: all .5s;/*자연스러운효과*/
}
#header .inner .logo div:nth-child(2){
transform:translateY(2px);
transition: all .5s;/*자연스러운효과*/
}
#header.on .inner .logo .sprite_insta_icon:after{
opacity: 0;
}
#header.on .inner .logo div:nth-child(2){
opacity: 0;
}
const heart = document.querySelector('.heart_btn');//단독실행하면 안됨
const header = document.querySelector('#header');
heart.addEventListener('click', function () {
console.log('하트누름 정상작동');
heart.classList.toggle('on');
});
function scrollFunc(){
console.log(pageYOffset);
if(pageYOffset >= 10){
header.classList.add('on');
}else{
header.classList.remove('on');
}
}
window.addEventListener('scroll', scrollFunc);
const heart = document.querySelector('.heart_btn');//단독실행하면 안됨
const header = document.querySelector('#header');
const sidebox = document.querySelector('.side_box');
heart.addEventListener('click', function () {
console.log('하트누름 정상작동');
heart.classList.toggle('on');
});
function resizeFunc() {
if (pageYOffset >= 10) {
let calcWidth = (window.innerWidth * 0.5) + 167; //웹페이지 기반 위치 재조정
sidebox.style.left = calcWidth + 'px';
}
}
function scrollFunc() {
console.log(pageYOffset);
if (pageYOffset >= 10) {
header.classList.add('on');
sidebox.classList.add('on');
} else {
header.classList.remove('on');
sidebox.classList.remove('on');
sidebox.removeAttribute('style');
}
}
window.addEventListener('scroll', scrollFunc);
function resizeFunc() {
if (pageYOffset >= 10) {
let calcWidth = (window.innerWidth * 0.5) + 167; //웹페이지 기반 위치 재조정
sidebox.style.left = calcWidth + 'px';
}
}
function scrollFunc() {
console.log(pageYOffset);
if (pageYOffset >= 10) {
header.classList.add('on');
sidebox.classList.add('on');
resizeFunc();
function resizeFunc() {
if (pageYOffset >= 10) {
let calcWidth = (window.innerWidth * 0.5) + 167; //웹페이지 기반 위치 재조정
sidebox.style.left = calcWidth + 'px';
}
if(matchMedia('screen and (max-width : 800px)').matches){
//여러 개의 컨텐츠 박스가 있으므로 배열 활용
for(let i=0; i<variableWidth.length;i++){
variableWidth[i].style.width = window.innerWidth - 20 + 'px';
}
}else{
for(let i=0; i<variableWidth.length;i++){
variableWidth[i].removeAttribute('style');
}
}
}