だから、これは私がこれまでに持っているものです: jsFiddle
HTML
<div style="height:1000px;">
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<div id="p_img" style="height:300px;">
<div target="p1" class="portfolio">1</div>
<div target="p2" class="portfolio">2</div>
<div target="p3" class="portfolio">3</div>
</div>
<div>
<div id="p1" class="description"> <a class="close">x</a>
AAA : Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
<div id="p2" class="description"> <a class="close">x</a>
BBB : Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
<div id="p3" class="description"> <a class="close">x</a>
CCC : Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
</div>
JavaScript (jQuery)
$(document).ready(function () {
$(".portfolio").click(function () {
$('.description').slideUp();
$('#' + $(this).attr('target')).slideDown();
$('html, body').animate({
scrollTop: $('#' + $(this).attr('target')).offset().top
}, 600);
});
$(".close").click(function () {
$('.description').slideUp();
$('html, body').animate({
scrollTop: $('#p_img').offset().top
}, 600);
});
});
CSS
.portfolio {
float:left;
width:100px;
height:100px;
background:#ccc;
margin:10px;
cursor:pointer;
}
.description {
float:left;
width:100%;
font-size:12px;
display:none;
}
.close {
float:left;
padding:5px;
background:red;
}
それはかなりうまくいっていますが、問題があります。
- 最初の灰色のボックスをクリックすると、その下に詳細が表示されます。
- 上にスクロールして (「x」ボタンはクリックしないでください)、2 番目の灰色のボックスをクリックします。
問題:
ページが下にスクロールしすぎて、灰色のボックス 2 の詳細の上部に到達していないことがわかります。
何をすべきか:
1 を開いて 2 をクリックすると、ページが 2 の詳細までスクロールダウンするはずです。