0
私はAngularJSには新しく、ディレクティブで作業するのに少し問題があります。AngularJSのさまざまな要素をホバリングするとdiv内に異なるコンテンツが表示される
現在、ナビゲーションメニューに取り組んでおり、達成しようとしているのは.services-content
の中にのメニュー内にli
のホバーを置くと表示されます。また、.services-content
は、どの要素がホバリングされているかに応じて背景色が変化します。背景色の部分が機能していますが、各項目のカスタムコンテンツをどのように表示するかわかりません。
私のhtml:
<div class="page-navigation row">
<div class="col-sm-4">
<!-- Some content here -->
</div>
<div class="col-sm-4">
<h6>Navigation</h6>
<nav>
<ul class="list-unstyled nav-list">
<!-- Here is my directive -->
<li class="services" showcontentonhover>
<ul class="list-unstyled">
<li>
<a href="fi.html">Go to Fi</a>
</li>
<li>
<a href="fa.html">Go to Fa</a>
</li>
<li>
<a href="fo.html">Go to Fo</a>
</li>
</ul>
</li>
<li>
<!-- some other link -->
</li>
<li>
<!-- some other link -->
</li>
<li>
<!-- some other link -->
</li>
</ul>
</nav>
</div>
<div class="col-sm-4 services-content">
<!-- I want my content to be here! -->
<p>Different paragraph for each li in .services</p>
<a href="foo">This anchor item should have the same href that the hovered element</a>
</div>
と私のディレクティブ:私が調査してきたように、私はこれは、ディレクティブのテンプレートを作成するか、おそらくtranscludeを使用して関連していると思う
app.directive('showcontentonhover',
function() {
return {
restrict: 'A',
link : function($scope, element, attrs) {
var el = element.find('li');
el.bind('mouseenter', function() {
$(this).siblings().removeClass('active-nav');
$(this).addClass('active-nav');
});
el.eq(0).bind('mouseenter', function() {
$('.services-content').css('background-color', '#14202B');
// Something should happen here that modifies the content of .services-content
});
el.eq(1).bind('mouseenter', function() {
$('.services-content').css('background-color', '#1858a5');
// Something should happen here that modifies the content of .services-content
});
el.eq(2).bind('mouseenter', function() {
$('.services-content').css('background-color', '#2196F3');
// Something should happen here that modifies the content of .services-content
});
}
}
});
正直なところ、私はちょっと失ってしまった。私は現在、AngularJSにdirective
と事前
は...私はいくつかのHTMLマークアップとcontentModel.textを適応させるつもり試みです別のケースごとに、もう一度感謝します=) –