JavaScriptコードは次のとおりです。
$(document).ready(function(){
// some code here
$('.show_hide').toggle(function(){
// some code here
},
function() {
// some code here
});
if ($('.wrapper').css('marginLeft') == "0px") {
$(".show_hide").hover(function () {
$(".wrapper").animate({ left: 20, opacity : 1 }, 300);
},
function () {
$(".wrapper").animate({ left:0, opacity : 1 }, 300);
})
}
else if ($('.wrapper').css('marginLeft') > "1px") {
$(".show_hide").hover(function () {
$(".wrapper").animate({ right:20, opacity : 1 },300);
},
function () {
$(".wrapper").animate({ right:0, opacity : 1}, 300);
})
}
});
ここで確認できるのは、ドキュメントの準備ができたら「ホバー」動作を一度定義することです。
一方、あなたがすべきことは、「トグル」イベント中にこの動作を再定義することです。
代わりにこのコードを使用することをお勧めします。
function setupHoverBehaviour() {
var marginValue = $('.wrapper').css('marginLeft');
if ( marginValue == "auto" || parseInt(marginValue) == "0" ) {
$(".show_hide").hover(function () {
$(".wrapper").animate({ left: 20, opacity : 1 }, 300);
},
function () {
$(".wrapper").animate({ left:0, opacity : 1 }, 300);
})
}
else {
$(".show_hide").hover(function () {
$(".wrapper").animate({ right:20, opacity : 1 },300);
},
function () {
$(".wrapper").animate({ right:0, opacity : 1}, 300);
})
}
}
$(document).ready(function(){
// some code here
$('.show_hide').toggle(function(){
// some code here
setupHoverBehaviour();
},
function() {
// some code here
setupHoverBehaviour();
});
setupHoverBehaviour();
});