最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to simulate as if user pressed Ctrl "plus" plus or minus using javascript (JQuery)? - Stack Overflow

programmeradmin1浏览0评论

Is this possible if I click on an anchor link to simulate as if I have pressed Ctrl+ keys on the keyboard (or equivalent on Mac)? if yes, could you show me how to do this, please?

something like

<a href="#" onclick="simulateCtrlKeyPlus();return false;">Ctrl+</a>

Is this possible if I click on an anchor link to simulate as if I have pressed Ctrl+ keys on the keyboard (or equivalent on Mac)? if yes, could you show me how to do this, please?

something like

<a href="#" onclick="simulateCtrlKeyPlus();return false;">Ctrl+</a>
Share Improve this question edited Jun 12, 2012 at 12:16 user1421214 asked Jun 12, 2012 at 11:18 user1421214user1421214 9094 gold badges17 silver badges25 bronze badges 0
Add a ment  | 

4 Answers 4

Reset to default 3

If you just want to simulate the behaviour of the CTRL+Mousewheel Zoom function, you can use CSS3-Transitions. A nice jQuery plugin for this is jquery Transit.

Example:

$('a.ctrlplus').click(function() {
  $('body').transition({ scale: ($('body').css('scale')+0.1) });
});

Don't know if it works in all Browsers.

I'm pretty sure you will need to access this on the browser API level, since not all browsers have this functionality or do it the same way.

I cannot understand what you are going to achieve, but here is a plugin, which made handling keyboard shortcuts very easier.

Here is an example

shortcut.add("Ctrl+Shift+X",function() {
alert("You have pressed Ctrl+____");
});  

Hope it will help you.

To simulate the zoom function, you can use CSS property "zoom". For JS, it's like:

function simulateCtrlKeyPlus() {
   let currentZoom = parseFloat(document.body.style.zoom) || 1
   document.body.style.zoom = currentZoom * 1.1
}
发布评论

评论列表(0)

  1. 暂无评论