私の問題: http ://www.danieldoktor.dk/test2/test2.html
いずれかの設定ボタンを押すと、両方のボックスがトリガーされます。
ボタンとスライドダウンアップボックスを同様のコードで制御する全体的なコードが欲しいのですが、両方を制御するのではなく、各ボックスを個別に制御します。
$(".someBtnClass").click(function () {
if(!$(".someBoxClass").hasClass('header-down')){
$(".someBoxClass").stop().animate({height:'100px'},{queue:false, duration:600, easing: 'linear'}).addClass('header-down');
}
else{
$(".someBoxClass").stop().animate({height:'30px'},{queue:false, duration:600, easing: 'linear'}).removeClass('header-down');
}
});
$(document).click(function() {
if($(".someBoxClass").hasClass('header-down')){
$(".someBoxClass").stop().animate({height:'30px'},{queue:false, duration:600, easing: 'linear'}).removeClass('header-down');
}
});
$(".someBoxClass").click(function(e) {
e.stopPropagation(); // This is the preferred method.
// This should not be used unless you do not want
// any click events registering inside the div
});
これはクラスで行うことができますか?
そうでない場合は、どのように作成できるので、後でボックスをphpでロードできますか?
編集
私のマークアップ:HTML
<div class="lists">
<header class="box_header" id="box1">
<h1>HEADER 1</h1>
<div class="setting" id="btn1"></div>
</header>
</div>
<div class="lists">
<header class="box_header" id="box2">
<h1>HEADER 2</h1>
<div class="setting" id="btn2"></div>
</header>
</div>
jQuery
$(".setting").each(function(){
$(this).on("click", function(){if(!$(".box_header").hasClass('header-down')){
$(".box_header").stop().animate({height:'100px'},{queue:false, duration:600, easing: 'linear'}).addClass('header-down');
}
else{
$(".box_header").stop().animate({height:'30px'},{queue:false, duration:600, easing: 'linear'}).removeClass('header-down');
}});
});
$(document).click(function() {
if($(".box_header").hasClass('header-down')){
$(".box_header").stop().animate({height:'30px'},{queue:false, duration:600, easing: 'linear'}).removeClass('header-down');
}
});
$(".box_header").click(function(e) {
e.stopPropagation(); // This is the preferred method.
// This should not be used unless you do not want
// any click events registering inside the div
});