Javascript 使用JQuery进行转换
在我的页面中,我有一些与anchor的链接和一些Javascript 使用JQuery进行转换,javascript,jquery,html,css,Javascript,Jquery,Html,Css,在我的页面中,我有一些与anchor的链接和一些divs: <nav id="Dnav"> <ul class="Dul"><a id="aone" href="#D1one">About</a></ul> <ul class="Dul"><a id="atwo" href="#D1two">Help</a></ul> <ul class="Dul">&
div
s:
<nav id="Dnav">
<ul class="Dul"><a id="aone" href="#D1one">About</a></ul>
<ul class="Dul"><a id="atwo" href="#D1two">Help</a></ul>
<ul class="Dul"><a id="athree" href="#D1three">Contact</a></ul>
<ul class="Dul"><a id="afour" href="#D1four">Hello</a></ul>
<ul class="Dul"><a id="afive" href="#D1five">hiya</a></ul>
</nav >
<div id="D1one"></div>
<div id="D1two"></div>
<div id="D1three"></div>
<div id="D1four"></div>
<div id="D1five"></div>
我有两个问题:
.scaleup
会被应用,但是当我单击其他链接时,.铰链
不会.hinge
类。但是,如果在单击第一个链接之后,.hinge
类将不会被应用var currentzindex=parseInt($(this).css(“zIndex”),10)
其中的z-index是否正确?不太清楚您想做什么,如果您试图在目标div中添加z-index
和类,您需要选择锚的href
@kittenz是,我只选择锚的href。Resultelement用于选择正在移出页面的div。我需要两个转换,一个用于目标div,另一个用于正在运行的divout@jai我今天才开始用jquery编写代码。如果我更改该值,z索引值可以正常工作,因为它没有按预期工作
$(document).ready(function () {
$("a").on("click",function () {
var highestzindex = 0;
var resultelement = null;
$('#D1one,#D1two,#D1three,#D1four,#D1five').addClass('hide');
$('div').each(function () {
var currentzindex = parseInt($(this).css("zIndex"), 10);
if (currentzindex > highestzindex) {
highestzindex = currentzindex;
resultelement = $(this);
resultelement.removeClass('hide');
resultelement.addClass('hinge');
resultelement.css('z-index', '3');
}
});
$($(this).attr("href")).removeClass('hide');
$($(this).attr("href")).addClass('scaleUp');
$($(this).attr("href")).css('z-index', '5');
});
});