javascript - Why jquery trigger doesn't work? -
this part should trigger click on image when #x present in browser url... never happens....
// var hash = window.location.hash.slice(1); if (hash) { $("#barely_slide img[data-imgnum='"+ hash +"']").trigger("click"); } else { move_slide(); }
actuall part needs triggered:
// $("#barely_slide article img").on("click", function(){ if ($(this).attr("class") == "focus") {return false;} // $("#barely_slide article img").removeclass("previous"); $("#barely_slide article .focus").addclass("previous"); var image = $(this); $(".previous").animate({"height":300,"margin-top":0}, "fast"); $("#barely_slide article .focus").removeclass("focus"); image.addclass("focus"); // window.location.hash = image.attr("data-imgnum"); // move_slide(); return false; });
remember attach click
handler before trigger it:
$("#barely_slide article img").on("click", function() { // attach click handler ... });
trigger (this must come after above):
$("#barely_slide img[data-imgnum='"+ hash +"']").trigger("click"); // or .click()
Comments
Post a Comment