TIL 23.10.16

ν™©μ€ν•˜Β·2023λ…„ 10μ›” 15일
0

TIL

λͺ©λ‘ 보기
98/146

πŸ“ŒToday I Learned

jQuery

ex05_css

CSS μ‘°μž‘

  1. css(속성) > 읽기
  2. css(속성, κ°’) > μ“°κΈ°

jQueryλ₯Ό μ“°λ©΄ κ°„λ‹¨ν•˜λ‹€.

//JavaScript > CSS μ‘°μž‘ > inline style sheet

//κ°’ 읽기
alert($("#box").css("color")); //rgb(0, 0, 0)

$("#box").css("color", "blue"); // return #box 객체

// 객체 ν˜•νƒœλ‘œ μ—¬λŸ¬ cssλ₯Ό μ“Έ 수 μžˆλ‹€.
$("#box").css({
  color: "blue",
  backgroundColor: "gold",
  fontSize: "3rem",
});

클래슀

// μΆ”κ°€
//BOM
// box.className='one';

//DOM
// box.classList.add('one');
// box.classList.remove('two');

//jQuery
$("#box").addClass("one");
$("#box").addClass("two");

//제거
$("#box").removeClass("two");

$("#box").toggleClass("two");

정리

  1. obj.css('attr')
  • 읽기
  1. obj.css('attr', 'value')
  • μ“°κΈ°
  1. obj.css('attr', 'value')
    .css('attr', 'value')
    .css('attr', 'value')
  2. obj.css({
    attr:value,
    attr:value,
    attr:value
    })
  3. obj.addClass('class')
  4. obj.removeClass('class')
  5. obj.toggleClass('class')

ex06_box

jQuery + Box Model

  1. CSS 속성
console.log("width", $("#box").css("width"));
console.log("width", $("#box").css("height"));
$("#box").css("width", "300px");

  1. μ „μš© λ©”μ†Œλ“œ(jQuery) > μˆ«μžν˜•(px)
console.log("width()", $("#box").width());
console.log("height()", $("#box").height());
$("#box").height(300);

  1. width/height + padding
console.log("innerWidth()", $("#box").innerWidth());
      console.log("innerHeight()", $("#box").innerHeight());

  1. width/height + padding = border = orange μ˜μ—­ + νŒŒλž€μƒ‰ ν…Œλ‘λ¦¬ > λˆˆμ— λ³΄μ΄λŠ” μ‹€μ œ μ‚¬κ°ν˜•
console.log("outerWidth()", $("#box").outerWidth());
console.log("outerHeight()", $("#box").outerHeight());

  1. width/height + padding = border + margin = orange μ˜μ—­ + νŒŒλž€μƒ‰ ν…Œλ‘λ¦¬ > μ‹€μ œ μ‚¬κ°ν˜•
console.log("outerWidth(true)", $("#box").outerWidth(true));
console.log("outerHeight(true)", $("#box").outerHeight(true));

ex07_manipulation

jQuery νƒœκ·Έ μ‘°μž‘

μ½˜ν…μΈ  μ‘°μž‘

  • innerText, textContext > text()
  • innerHTML > html()
  • value > val()
//text()
$("#box").text("홍길동"); // μ“°κΈ°
alert($("#box").text()); //읽기

//html()
$("#box").html("<b>μ•ˆλ…•ν•˜μ„Έμš”.</b>");
alert($("#box").html());

//val()
$("#txt1").val("κΈ°λ³Έκ°’");
alert($("#txt1").val());

HTML 속성 μ‘°μž‘

//BOM
//- obj.prop          > 읽기
//- obj.prop = value; > μ“°κΈ°

//DOM
//- obj.getAttribute('prop');         > 읽기
//- obj.setAttribute('prop', value);  > μ“°κΈ°

//*** attr(), prop() > λ§ˆμŒλŒ€λ‘œ μ‚¬μš© > 문제 λ°œμƒ > μ„œλ‘œ ꡐ체
//jQuery
//1. HTML의 속성을 μ œμ–΄
// $("#txt1").attr("size", 50);
// alert($("#txt1").attr("size"));

//2. JavaScript의 ν”„λ‘œνΌν‹°λ₯Ό μ œμ–΄
$("#txt1").prop("size", 50);
alert($("#txt1").prop("size"));

ex08


ex09


ex10

슀크둀 인디케이터 λ°” 생성

$(document).scroll(function () {
  // console.log($(document).scrollTop());

  // λ¬Έμ„œμ˜ μ„Έλ‘œκΈΈμ΄(μŠ€ν¬λ‘€λ°” μ΅œλŒ€ μœ„μΉ˜) : 100%
  // = μŠ€ν¬λ‘€λ°” μœ„μΉ˜ : x

  let x =
      ($(document).scrollTop() * 100) /
      ($(document).outerHeight() - $(window).outerHeight());

  $("#bar").css("width", x + "%");
});

ex11

슀크둀 인디케이터 λ°” λͺ¨λ“ˆν™”ν•˜κΈ°

profile
μ°¨κ·Όμ°¨κ·Ό ν•˜λ‚˜μ”©

0개의 λŒ“κΈ€