我想在用户按下“Escape”键时触发刷新事件,或者更愿意在按下 Esc 键时触发图像点击事件实现此目的的最佳方法是什么?谢谢
$clone.click(function (e) { //action when magnified image is clicked on
var $this = $(this)
var imageinfo = $this.data('$relatedtarget').data('imgshell')
jQuery.imageMagnify.refreshoffsets($(window), $this.data('$relatedtarget'), imageinfo) //refresh offset positions of original and warped images
$this.stop().animate({ opacity: 0, left: imageinfo.attrs.x, top: imageinfo.attrs.y, width: imageinfo.attrs.w, height: imageinfo.attrs.h }, setting.duration,
function () {
$this.hide()
$this.data('$relatedtarget').css({ opacity: 1 }) //reveal original image
}) //end animate
}) //end click
//This is what I put in, but I'd like it to not just refresh but actually perform the same function as OnClick as above
$(document).keyup(function (e) { //action when magnified image is clicked on
if (e.keyCode == 27) { //escape key
window.location.reload();
}
}) //end click
$clone.keyup(function (e) { //action when 'Esc' key is pressed after magnifying image
if (e.keyCode == 27) { //escape key
var $this = $(this)
var imageinfo = $this.data('$relatedtarget').data('imgshell')
jQuery.imageMagnify.refreshoffsets($(window), $this.data('$relatedtarget'), imageinfo) //refresh offset positions of original and warped images
$this.stop().animate({ opacity: 0, left: imageinfo.attrs.x, top: imageinfo.attrs.y, width: imageinfo.attrs.w, height: imageinfo.attrs.h }, setting.duration,
function () {
$this.hide()
$this.data('$relatedtarget').css({ opacity: 1 }) //reveal original image
}) //end animate
}
}) //end
}
};