jquery を使用して動的にページに画像を追加しています。基本的に、ページ上の画像の「ピクセル-y / 低解像度」バージョンを作成し、オリジナルの上にページの読み込みを追加しています。次に、典型的な「ホバーでフェードアウト」するものは、マウスオーバーでそれらをフェードアウトし、元の信号を表示する必要があります。
だから私は入ってくる画像を持っています..しかし、どういうわけかホバーリスナーが接続されていません。最初はホバーしようとしましたが、トラブルシューティングが簡単になったという理由だけで、今はクリックしています。何もない。
.on() 関数は、動的に追加されたアイテムにもアタッチする必要がありますよね? 何がうまくいかないのですか?エラーは発生しません。うまくいきません。
$.ajax({
type:"POST",
url:"js/pixelsandwich/pixelsandwich.php",
data:{src:src},
success:function(response){ // if there is already a "lo-rez" image, I get that URL.. if there isn't, one is created and I return that URL
newImg = $("<img class='crunched'>"); // create the new <img>
newImg.attr('src', response); // assign the source
frame = $that.parent(); // grab the containing frame
frame.append(newImg); // add the new image. css:position:absolute and z-index take care of the rest
}
});
$(".crunched").on("click", function(){ // << this just isn't attaching at all
alert("hello");
$(this).fadeTo('slow',0.5);
});
誰か助けてくれませんか?