简体   繁体   English

仅在单击正确的符号时打开手风琴

[英]Open Accordion only on click of the right symbol

I would like to disable the click event that opens the accordion if I click anywhere on the heading.Instead I would like to click only on the right most symbol.... Here it's opening if I click on the Save button.. 如果要在标题上单击任意位置,我想禁用打开手风琴的click事件。相反,我只想单击最右边的符号。...如果单击“保存”按钮,它将在此处打开。

  <accordion-group is-open="status.open" template-url="accordion-group.html">
        <accordion-heading>
            I can have markup, too! <button type="button">Save</button> <i class="pull-right glyphicon" ng-class="{'glyphicon-chevron-down': status.open, 'glyphicon-chevron-right': !status.open}"></i>
        </accordion-heading>
        This is just some content to illustrate fancy headings.
    </accordion-group>

Here's the plunker.. 这是小矮人

link 链接

in your html file i modified: 在我修改的html文件中:

  <accordion close-others="oneAtATime">
    <accordion-group style="pointer-events:none !important;" is-open="status.open" template-url="accordion-group.html">
        <accordion-heading style="pointer-events:none !important;">
            I can have markup, too! <button style="pointer-events:none !important;" type="button">Save</button> <i class="pull-right glyphicon" style="pointer-events:auto !important;" ng-class="{'glyphicon-chevron-down': status.open, 'glyphicon-chevron-right': !status.open}"></i>
        </accordion-heading>
        This is just some content to illustrate fancy headings.
    </accordion-group>
  </accordion>

You should add css property: "pointer-events: none !important" on elements which you won't to react on mouse click event, and set "pointer-events: auto !important" on your icon indicator only. 您应该在元素上添加css属性:“ pointer-events:none!important”,而鼠标单击事件不会对其做出反应,并仅在图标指示器上设置“ pointer-events:auto!important”。 The accordion should be opened only when you click on the arrow icon. 仅当您单击箭头图标时,手风琴才应打开。 That should work :) 那应该工作:)

To make your solution more elegant you can make CSS classes like: 为了使您的解决方案更加优雅,可以使CSS类如下:

.disable-click-event {
    pointer-events: none !important;
}

.enable-click-event {
    pointer-events: auto !important;
}

There's also an option that prevents event bubbling ($event.stopPropagation()) but in this case i dont know where exactly event is invoked so it needs hard investigation to find it out. 还有一个选项可以防止事件冒泡($ event.stopPropagation()),但在这种情况下,我不知道确切地在何处调用了事件,因此需要进行认真的调查才能找到它。

One more hint: if any problem can be solve with CSS instead of JS it's completly worth to do it :) JavaScript events are not so easy to debug, so CSS fix will be much faster to find than dirty bug with event bubbling. 还有一个提示:如果可以用CSS而不是JS解决任何问题,那么完全值得这样做:) JavaScript事件不是那么容易调试,因此,比起带有事件冒泡的肮脏bug,发现CSS修复要快得多。 I can recommend you to use simple CSS solutions with a clear conscience :) cheers 我可以建议您使用具有明确意识的简单CSS解决方案:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM