如何在Angular2中打开长按或右键单击菜单

时间:2017-06-05 11:40:47

标签: angular typescript

我正在玩角度2.我想在手机和电脑上打开2,3个选项的菜单。

我需要的是,当我长时间按住或右键单击div class 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.
}

我应该在哪里打电话给这个菜单,请指导。

1 个答案:

答案 0 :(得分:1)

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

组件

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 
  }
}
相关问题