3
Th函數工作得很好。懸停的jquery動畫邊框
當鼠標移動到不同的鏈接上時,這個想法是讓某種類型的背景(背景或下劃線)跟着你,當你將鼠標放在不同的鏈接上時,它會計算出左側的定位和寬度和動畫匹配。
我需要解決什麼問題?
- 在鼠標離開或鼠標移出高亮邊框應該回去的活動項目
- 活動項目應該永遠是起點一個突出的。
如果您需要更多信息,請詢問 我不確定我錯過了什麼。
$(function() {
$(".app-promo-img-align:first").addClass("active");
$('.app-promo-images').find('.app-promo-img-align').click(function(e) {
e.preventDefault;
$(".app-promo-img-align").removeClass("active");
$(this).addClass("active");
});
var $el, leftPos, newWidth,
$mainNav = $(".menu");
$mainNav.append("<div id='magic-line'></div>");
var $magicLine = $("#magic-line");
$magicLine
.width($(".app-promo-img-align.active").width())
.css("left", $(".app-promo-img-align.active a").position().left)
.data("origLeft", $magicLine.position().left)
.data("origWidth", $magicLine.width());
$(".menu li a").hover(function() {
$el = $(this);
leftPos = $el.position().left;
newWidth = $el.parent().width();
$magicLine.stop().animate({
left: leftPos,
width: newWidth
});
}).click(function() {
$mainNav.find('li').removeClass('active');
$(this).parent().addClass('active');
$magicLine.animate({
left: $(".app-promo-img-align.active a").position().left,
width: $(".app-promo-img-align.active").width()
});
});
$('.menu li:not(".app-promo-img-align.active")').hover(
function() {
$('#magic-line').addClass('hover');
},
function() {
$('#magic-line').removeClass('hover');
}
);
});
.bg {
height: 300px;
background: #000;
padding-top: 50px;
}
.menu {
padding: margin: 0 auto;
list-style: none;
position: relative;
display: flex;
justify-content: space-between;
max-width: 400px;
width: 100%;
}
.menu li {
display: inline-block;
}
.menu li a {
background: #bbb;
width: 80px;
height: 80px;
display: block;
float: left;
text-decoration: none;
text-transform: uppercase;
}
.menu li a:hover {
color: white;
}
#magic-line {
position: absolute;
top: -6px;
left: 0;
width: 100px;
height: 4px;
background: #fe4902;
-webkit-transition: background 400ms ease-in-out;
-moz-transition: background 400ms ease-in-out;
-ms-transition: background 400ms ease-in-out;
-o-transition: background 400ms ease-in-out
}
#magic-line.current_page_item {
position: absolute;
top: -2px;
left: 0;
width: 100px;
height: 2px;
background: #fe4902;
}
#magic-line.hover {
background: #fe4902;
-webkit-transition: background 400ms ease-in-out;
-moz-transition: background 400ms ease-in-out;
-ms-transition: background 400ms ease-in-out;
-o-transition: background 400ms ease-in-out;
transition: background 400ms ease-in-out;
}
.app-promo-img-align a {
position: relative;
}
.app-promo-img-align.active a {
width: 93px;
height: 93px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="bg">
<div class="nav-wrap">
<ul class="group menu app-promo-images" id="example-one">
<li class="app-promo-img-align">
<a href="#"></a>
</li>
<li class="app-promo-img-align">
<a href="#"></a>
</li>
<li class="app-promo-img-align">
<a href="#"></a>
</li>
<li class="app-promo-img-align">
<a href="#"></a>
</li>
</ul>
</div>
</div>
這是一個好太,感謝您的幫助 – user3699998