リンクがクリックされたときにリンクの下に追加しようとしdiv
ています。次のリンクがクリックされた後にそのボックスが消え、次のリンクの下に別のdivボックスが表示されます。
これが私が取り組んでいるフィドルです:http://jsfiddle.net/d0okie0612/geJM3/
HTML:
<div id="blackbar">
<a class="link" href="#">Click here</a>
<a class="link2" href="#">Click here</a>
<a class="link3" href="#">Click here</a>
</div>
JavaScript:
$('a.link').on('click', function (e) {
e.preventDefault();
$('<div class="whitebar"><p>1</p></div>').appendTo('div#blackbar');
});
$('a.link2').on('click', function (e) {
e.preventDefault();
$('<div class="whitebar2"><p>2</p></div>').appendTo('div#blackbar');
});
$('a.link3').on('click', function (e) {
e.preventDefault();
$('<div class="whitebar3"><p>3</p></div>').appendTo('div#blackbar');
});
CSS:
#blackbar { background: black; width: 900px; height: 200px;}
.whitebar { background: white; width: 40px; height: 30px; border: solid purple; z-index: 1000;}
.whitebar2 { background: white; width: 40px; height: 30px; border: solid purple; z-index: 1000; position: absolute; left: 90px;}
.whitebar3 { background: white; width: 40px; height: 30px; border: solid purple; z-index: 1000; position: absolute; left: 190px;}
a { color:white;}
私はまだjQueryを学んでいます、このコードは改善できると確信しています。
どんな助けでもいただければ幸いです。