以前は存在しなかったdivを表示し、Jqueryを使用するときにそれを削除する場合のベストプラクティスは何か疑問に思っています。ライトボックスやソートのようなモーダルポップアップボックスのように...
私のページにはポップアップショッピングカートがあり、それはある意味で機能します。元々、ショッピングカートを0にフェードさせていました。しかし、そうすると、下のhtmlをクリックできなくなります...そこで、ショッピングカートのdivを右に移動して、フェードさせました。次に、「カート」ボタンをクリックすると、すべてのスタイルが再び通常にリセットされます。もっときれいな方法があるのだろうかと思っていました。divをフェードアウトしてから、divを無効にして、下のhtmlをクリックできるようにします。したがって、ポップアップdivを大量のcssで移動する必要はありません。
これが私の現在のコードです:
document.getElementById("shopping-container").style.position="absolute";
document.getElementById("shopping-container").style.left="2000px";
$(".open").click(function() {
$("#shopping-container").stop().animate({"opacity": "1"}, "fast", function(){
document.getElementById("shopping-container").style.position="relative";
document.getElementById("shopping-container").style.top="150px";
});
});
$(".close").click(function() {
$("#shopping-container").stop().animate({"opacity": "0"}, "fast", function(){
document.getElementById("shopping-container").style.position="absolute";
document.getElementById("shopping-container").style.left="2000px";
});
});