ウィンドウのサイズが設定値を超えたときにアコーディオン ウィジェットを削除する際に問題が発生しました。
jQuery 1.8.3 と jQuery UI 1.9.2 を使用しています。
これは私のコードです:
/*
* Detect browser size and add accordian on page (at load) if necessary
*/
$(document).ready(function() {
var window_width = $(window).width();
if (window_width <= 767){
$("div.innernav ul.menu").accordion({
header: '.separator',
animated: 'slide',
event: "click",
heightStyle: "content",
icons: { "header": false, "headerSelected": false } ,
collapsible: true,
active: false,
});
}
});
/*
* Detect browser size on resize and add/remove accordian
*/
$(window).resize(function() {
var wi = $(window).width();
if (wi <= 767){
$("div.innernav ul.menu").accordion({
header: '.separator',
animated: 'slide',
event: "click",
heightStyle: "content",
icons: { "header": false, "headerSelected": false } ,
collapsible: true,
active: false,
});
} else if (wi >= 768){
$("div.innernav ul.menu").accordion("destroy");
}
});
コードは機能し、ウィンドウの幅が 768px より小さい場合にのみアコーディオンがアクティブになりますが、次のようになります。
Error: cannot call methods on accordion prior to initialisation; attempted to call method 'destroy'
このエラーにより、ページにある他のコードが壊れているように見えるので、このエラーを削除することができます。私はjavascript/jQueryの初心者なので、助けていただければ幸いです。
どうもありがとう!