我有一個工作代碼來關閉使用jQuery的自定義彈出窗口,但我想要一個使用AngularJS而不是jQuery的解決方案。 任何人都可以幫助我在AngularJS中找到this.closest()
。AngularJS中最接近的父選擇器
我想隱藏.popOverlay
點擊使用AngularJS的.popClose
,而不是jQuery。我不想使用perticular class/id becoz我有很多像這樣的彈出窗口,我想爲它們提供一個通用的解決方案。
這是我工作的jQuery代碼:
function popClose(e)
{
\t $(e).closest('.popOverlay').fadeOut('slow');
}
.popOverlay { background:rgba(0,0,0,.5); width:100%; height:100%; overflow-y:auto; position:fixed; left:0; top:0;}
.popBox { background:#fff; border-radius:5px; position:relative; width:400px; max-width:90%; padding:20px; margin-left:auto; margin-right:auto; margin-top:50px;}
.popClose { display:inline-block; position:absolute; top:5px; right:10px; cursor:pointer; color:#f00; font:bold 16px Arial, Helvetica, sans-serif;}
.heading { color:#0077c8; font:bold 16px Arial, Helvetica, sans-serif; margin-top:0;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="popOverlay">
\t <div class="popBox">
\t \t <a class="popClose" onClick="popClose(this)">x</a>
\t \t <h3 class="blue-heading">This is a custom popup.</h3>
\t </div>
</div>
您想要Angular solution:'ngIf'。 – dfsq
是的,我想使用AngularJS而不是jQuery來點擊'.popClose'來隱藏'.popOverlay'。也可以考慮我不想使用perticular class/id becoz我有很多喜歡它的彈出窗口,我想爲它們提供通用的解決方案。 –