按键事件
当单击放大的图像时,此功能返回到缩略图视图....
$('#wrapper > img').live('click',function(){
$this = $(this);
$('#description').empty().hide();
$('#thumbsWrapper').css('z-index','10')
.stop()
.animate({'height':'100%'},speed,function(){
var $theWrapper = $(this);
$('#panel').css('height','0px');
$theWrapper.css('z-index','0');
/*
remove the large image element
and the navigation buttons
*/
$this.remove();
$('#prev').hide();
$('#next').hide();
});
});
...除了单击之外,我希望它也可以在按键时关闭,或者如果可能的话只关闭“Esc”?
非常感谢
This function returns to the thumbnail view when clicked on the enlarged image....
$('#wrapper > img').live('click',function(){
$this = $(this);
$('#description').empty().hide();
$('#thumbsWrapper').css('z-index','10')
.stop()
.animate({'height':'100%'},speed,function(){
var $theWrapper = $(this);
$('#panel').css('height','0px');
$theWrapper.css('z-index','0');
/*
remove the large image element
and the navigation buttons
*/
$this.remove();
$('#prev').hide();
$('#next').hide();
});
});
... besides click, I want it also close on keypress or just 'Esc' if possible?
Many thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当页面加载时,我会将
keyup
事件绑定到document
,以检查是否按下了 ESC。尝试一下: http://jsfiddle.net/AXMGM/
jQuery 规范化
event.which
,以便它可以用来代替charCode
和keyCode
。来自文档 -
I'd bind a
keyup
event to thedocument
when the page loads, which checks if ESC was pressed.Try it out: http://jsfiddle.net/AXMGM/
jQuery normalizes the
event.which
such that it can be used in place ofcharCode
andkeyCode
.From the docs -
如果你想绑定转义,你可以检查 keypress/keydown 是否是转义键,如果是,则使用它,否则不执行任何操作。
If you want to bind escape you can check on keypress/keydown if the key is escape, and if so, use it, otherwise do nothing with it.