스크롤 위치에 따라 변하는 애니메이션 강의부터 보면 된다.
{"brand" : "Hyundai", "model" : "Kona", "price" : 30000, "img" : "https://codingapple1.github.io/kona.jpg"}
//bootstrap card참고
<div class="card">
<img src="..." class="card-img-top" alt="..." />
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">
Some quick example text to build on the card title and make up the
bulk of the card's content.
</p>
<a href="#" class="btn btn-primary">Go somewhere</a>
</div>
</div>
//버튼 클릭시, 데이터 받아오고, 화면에 표시
$(".show-product-btn").on("click", function () {
$.ajax({
url: "https://codingapple1.github.io/data.json",
type: "GET",
}).done(function (e) {
$(".card-title").html(e.model);
$(".card-text").html(e.price);
$(".card-img-top").attr("src", e.img);
});
});
$.ajax({
url: "https://codingapple1.github.io/data.json",
type: "GET",
})
객체
형태로 저장되어있다.e.model
객체 형태로 써야 한다..done(function (e) {
$(".card-title").html(e.model);
$(".card-text").html(e.price);
$(".card-img-top").attr("src", e.img);
});
ajax
이용하여 데이터를 요청하여 받아온다.image {
position: sticky;
top: 150px;
}
<body style="background-color: grey; height: 3000px">
<div class="grey"> //부모div
<div class="image"> //이미지 담는 div
<img src="img/cat.jpg" width="100%" /> //이미지
</div>
</div>
</body>
<body style="background-color: grey; height: 3000px">
<div class="grey">
<div class="image">
<img src="img/cat.jpg" width="100%" />
</div>
<div class="text">
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Magnam id ad
voluptatum ratione quis doloremque? Rem, provident, modi minima odit
repudiandae explicabo magni consequuntur cum odio cupiditate labore
dolorem iste!
</div>
<div class="text" style="margin-top: 300px">
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Magnam id ad
voluptatum ratione quis doloremque? Rem, provident, modi minima odit
repudiandae explicabo magni consequuntur cum odio cupiditate labore
dolorem iste!
</div>
</div>
</body>
float: right;
float: left;
position: sticky;
top: 150px;
.grey {
background-color: lightgrey;
margin-top: 500px;
height: 2000px;
}
.image {
float: right;
width: 400px;
position: sticky;
top: 150px;
}
.text {
float: left;
width: 300px;
}