私は自分で javascript と jquery を教えているので、これはちょっと低俗な質問かもしれませんし、コードが多すぎて誰もが通り抜けられないかもしれませんが、フィードバックを期待しています。私は周りを見回しましたが、私の質問をきちんと扱っているように見えるスレッドを見つけていません.
cms indexhibit を使用して (新しいタグを作成できません!)、生成されたメニュー リストからアコーディオン スタイルのメニューを作成しようとしています。私は基本的に、既存の作業を変更した後の動作を持っていますが、.click と .toggle の間の競合と混乱した使用 if ステートメントである疑いのないかなりの数の欠点があります。
私は基本的にゼロから始めてこれをやり直したいので、a) 間違いから学び、b) 何が起こっているのかを理解できます。ここからどこへ行くべきか、またはトラブルシューティングの方法がわからないため、現在問題が発生しています。
ドキュメントのヘッダーにあるスクリプトがどのように連携するかを簡単に分析できる人はいますか? また、私が見ている紛争の性質と、それらを改善するためにどのようなアプローチが必要かについての洞察はありますか? 新たに始めるとしたら、どのようなアプローチをとりますか?
これが実際に動作していることを確認するためのテストです(疣贅とすべて):http://stillstatic.nfshost.com/
このスクリプトはドキュメント ヘッドに入ります。
<script type='text/javascript'> //im not entirely clear as to what this achieves
path = 'path/to/script/';
$(document).ready(function() {
setTimeout('move_up()', 1);
expandingMenu(0);
expandingMenu(1);
expandingMenu(2);
expandingMenu(3);
expandingMenu(4);
//etc
});
</script>
生成されたリスト:
<ul>
<li class='section-title active_menu'>blogs</li>
<li><a class="active" href='#' onclick="do_click();">3</a></li>
</ul>
<ul> //this menu section dose not have a label: class .section-title
<li><a href='#' onclick="do_click();">1</a></li>
<li><a href='#' onclick="do_click();">2</a></li>
</ul>
<ul> //this menu section is not the 'active menu' this is achieved by the jquery script
<li class='section-title'>writing</li>
<li><a href='#' onclick="do_click();">4</a></li>
<li><a href='#' onclick="do_click();">5</a></li>
</ul>
外部スクリプトの要点:
function expandingMenu(num) {
var speed = 500;
var menu_title = $("#menu ul").eq(num).children(":first"); // ie. first child be the title with the class .section-title unless the user turned it off
var menu_items = $("#menu ul").eq(num).children().filter(function (index) { return index > 0; }); // ie. any li NOT in position 0, below li.section-title
if (menu_items.is(".active") == true) {
menu_title.addClass("active_menu"); //Add a class to the active list so we can style it.
}
if (menu_title.is(".section-title") == true){ // this if prevents interference with users who turn off the section titling
if ((menu_items.is(".active") == false) && (menu_items.is(":visible")) ) {
menu_items.hide(0);// first we hide the inactive exhibits
}
$('li').click(function (){
if ( (menu_title.is(":visible") == true) ){
menu_items.hide(speed);
}
if ( (menu_items.is(":hidden") == true ) && (('')) ){// ?! without this EMPTY second condition things break down??? hu?. . .
menu_items.show(speed);
}
})
menu_title.css({cursor:"pointer"}).toggle( // add click functions + pointer to menu_title
function () {
menu_items.show(speed);//Open it up
},
function () {
// this function could even be empty but without a pointless 'if' things get really weird
if (menu_items.is(".xx"))
menu_items.hide(speed); //Take the menu item off of active duty!
}
)
}
}