2017-06-05 50 views
0

我正在玩角2,我想打开一个菜单,在移动设备上以及在PC上的2,3选项。如何打开一个长按住或右键单击Angular2的菜单

我需要的是,当我长保持或divclass container上面点击右键,我希望有一个菜单中打开这样的 - 如下

Image

HTML代码:

<div class="container" id="main-wrapper" > 
    <section class="intro"> 
    <div class="content" > 
    <h1 [contentEditable]="contentEditable" >You can create full screen sections without javascript.</h1> 
    <p [contentEditable]="contentEditable">The height is set to 90vh, that means 90% height.</p> 
</div> 
</section> 
</div> 

explore.ts

rightClickMenu(){ 
// What should i write in this function to get a menu as explained. 
} 

我应该在哪里调用这个菜单,请指导。

+0

检查此[Plunkr](http://plnkr.co/edit/3klGukkbDBCOaBYqcGmr?p=preview)。 –

回答

0

如果时间>时间指定,则计算鼠标向上事件和鼠标向下事件之间的时间,然后显示菜单。

在组件

timeInterval:int =0 
var k; 
doMouseDown() 
{ 
    timeInterval=0; 
    k=setInterval(function(){ 
    timeInterval++; 
},1000); 
} 

doMouseUp() 
{ 
    clearInterval(k); 
    if(timeInterval >15) // replace 15 with your time for long hold) 
    { 
    //open menu 
    } 
    else 
    { 
    //show for short hold 
    } 
} 
+0

你可以通过显示如何在我的html上实现它,以及我在我的ts文件中写什么,这将会有所帮助。我得到先进的例子,我无法实现这些 –

+0

我可以通过使用本教程-blog.sodhanalibrary.com/2016/10/display-customized-context-menu-on.html右键单击它来生成菜单,但在右击时默认的浏览器窗口也会打开,我们如何才能关闭它,只有我们的窗口打开,目前正在发生 - https://www.dropbox.com/s/wqxkgfpozftsthe/Screenshot%202017-06-06% 2000.48.23.png?dl = 0,请指导 –

相关问题