JavaScript 或 CSS - 几乎可以工作,遇到一些障碍
javascript or css - almost working, running into some snags
下面我将提供我目前拥有的代码 - html,css和javascript。 除了一件小事外,一切都正常工作,我似乎无法弄清楚。 我对 javascript 仍然相当陌生,并认为需要 javascript 来完成这项工作,如果没有 - 它必须在我的 css 中......
如果您单击每个带有标题(NoS 成员)、(注册成员)和(团队配置文件)的div,您将看到滑块背景图像(小三角形)工作并在单击三个div 中的任何一个时处于活动状态 - 这样做会打开它下面的另一个容器。 这一切都完美无缺,但是,我遇到的问题是,如果您先单击(NoS 成员)一个,然后依次向右并单击第二个 - (注册成员)或最后一个(团队资料),然后尝试单击第二个 - (注册成员)或第一个 - (NoS 成员), 滑块向左滑动时不起作用。 它似乎只有在单击发生后才能向右滑动。
这是我得到的jsfidd:http://jsfiddle.net/5DTKH/
法典:
.HTML
<div id="profile_selection">
<a href="#nos_profiles" class="profile_selection">{Ñا}<br />Members</a>
<a href="#registered_profiles" class="profile_selection">Registered<br />Members</a>
<a href="#team_profiles" class="profile_selection">Team<br />Profiles</a>
<div id="profile_selection_slider"></div>
</div>
<div id="nos_profiles" class="selection">
</div>
<div id="registered_profiles" class="selection">
</div>
<div id="team_profiles" class="selection">
</div>
.CSS
#profile_selection { width: 612px; height: 152px; padding: 0; margin: 15px auto; position: relative; }
#profile_selection a {
width: 200px;
height: 105px;
padding: 45px 0 0 0;
margin: 0;
background: #333;
border: 2px solid #444;
-moz-border-radius: 25px;
-webkit-border-radius: 25px;
border-radius: 25px;
-moz-box-shadow: inset 0 -0.3em 0.9em 0.3em #000, 0 28px 24px -24px #000;
-webkit-box-shadow: inset 0 -0.3em 0.9em 0.3em #000, 0 28px 24px -24px #000;
box-shadow: inset 0 -0.3em 0.9em 0.3em #000, 0 28px 24px -24px #000;
float: left;
-moz-transition: all .2s ease;
-webkit-transition: all .2s ease;
-o-transition: all .2s ease;
transition: all .2s ease;
color: #FFF;
font: 24px Arial, Helvetica, sans-serif;
font-weight: bold;
font-variant: small-caps;
text-align: center;
text-decoration: none;
text-shadow: 1px 1px 1px #000, -2px -2px 2px #000;
position: relative;
z-index: 4;
}
#profile_selection a:hover, #profile_selection a.active {
height: 100px;
padding: 50px 0 0 0;
background: #222;
-moz-box-shadow: inset 0 0.3em 0.9em 0.3em #000;
-webkit-box-shadow: inset 0 0.3em 0.9em 0.3em #000;
box-shadow: inset 0 0.3em 0.9em 0.3em #000;
color: #DF7401;
}
/* ===== Start of 'Profile - Selection - Slider' ===== */
#profile_selection_slider {
width: 64px;
height: 16px;
background: url(http://www.nosclan.net/images/Home/menu_bg_hover.png) no-repeat 0 0 transparent;
-moz-transition: all .2s ease-in-out;
-webkit-transition: all .2s ease-in-out;
-o-transition: all .2s ease-in-out;
transition: all .2s ease-in-out;
position: absolute;
top: 152px;
left: 275px;
z-index: 4;
}
#profile_selection a:nth-of-type(1):hover ~ #profile_selection_slider, #profile_selection a:nth-of-type(1).active ~ #profile_selection_slider{ left: 71px; }
#profile_selection a:nth-of-type(2):hover ~ #profile_selection_slider, #profile_selection a:nth-of-type(2).active ~ #profile_selection_slider { left: 275px; }
#profile_selection a:nth-of-type(3):hover ~ #profile_selection_slider, #profile_selection a:nth-of-type(3).active ~ #profile_selection_slider { left: 480px; }
/* ===== Start of 'NoS - Profiles' ===== */
#nos_profiles {
width: 950px;
height: 520px;
padding: 0;
margin: 0 auto;
background: #222;
border: 2px solid #444;
border-bottom: none;
-moz-border-radius: 12px 12px 0 0;
-webkit-border-radius: 12px 12px 0 0;
border-radius: 12px 12px 0 0;
-moz-box-shadow: inset 0 0.3em 0.9em 0.3em #000;
-webkit-box-shadow: inset 0 0.3em 0.9em 0.3em #000;
box-shadow: inset 0 0.3em 0.9em 0.3em #000;
display: none;
position: relative;
top: -15px;
z-index: 1;
}
/* ===== Start of 'Registered - Profiles' ===== */
#registered_profiles {
width: 950px;
height: 520px;
padding: 0;
margin: 0 auto;
background: #222;
border: 2px solid #444;
border-bottom: none;
-moz-border-radius: 12px 12px 0 0;
-webkit-border-radius: 12px 12px 0 0;
border-radius: 12px 12px 0 0;
-moz-box-shadow: inset 0 0.3em 0.9em 0.3em #000;
-webkit-box-shadow: inset 0 0.3em 0.9em 0.3em #000;
box-shadow: inset 0 0.3em 0.9em 0.3em #000;
display: none;
position: relative;
top: -15px;
z-index: 1;
}
/* ===== Start of 'Team - Profiles' ===== */
#team_profiles {
width: 950px;
height: 520px;
padding: 0;
margin: 0 auto;
background: #222;
border: 2px solid #444;
border-bottom: none;
-moz-border-radius: 12px 12px 0 0;
-webkit-border-radius: 12px 12px 0 0;
border-radius: 12px 12px 0 0;
-moz-box-shadow: inset 0 0.3em 0.9em 0.3em #000;
-webkit-box-shadow: inset 0 0.3em 0.9em 0.3em #000;
box-shadow: inset 0 0.3em 0.9em 0.3em #000;
display: none;
position: relative;
top: -15px;
z-index: 1;
}
爪哇语
$(document).ready(function(){
$('a.profile_selection').click( function(){
var a = $(this);
$('a.profile_selection').removeClass('active');
$(this).addClass('active');
var selection = $( a.attr('href'));
selection.removeClass('selection');
$('.selection').hide();
selection.addClass('selection');
if( selection.is(':visible')){
selection.slideToggle(400)
}else{selection.slideToggle(400)
};
});
});
任何帮助将不胜感激 - 不确定这是否重要,但我正在使用 jquery 库 1.3.2 - 我知道它已经过时了,但它就是这样......
最后,我确实想再次感谢Ashis和Nick帮助我解决与此相关的另一个问题。
我在上面的代码中做了一些更改,并在这里更新了小提琴小提琴
$(document).ready(function(){
var clicked;
$('a.profile_selection').click( function(){
var a = $(this);
clicked=$(this);
$('a.profile_selection').not(clicked).removeClass('active');
$(this).addClass('active');
var selection = $( a.attr('href'));
selection.removeClass('selection');
$('.selection').hide();
selection.addClass('selection');
if( selection.is(':visible')){
selection.slideToggle(400)
}else{selection.slideToggle(400)
};
});
$('a.profile_selection').hover(function(){
var a = $(this);
$('a.profile_selection').not(clicked).removeClass('active');
$(this).addClass('active');
})
});
你可以从这里将你的CSS行53更改为55
#profile_selection a:nth-of-type(1):hover ~ #profile_selection_slider, #profile_selection a:nth-of-type(1).active ~ #profile_selection_slider{ left: 71px; }
#profile_selection a:nth-of-type(2):hover ~ #profile_selection_slider, #profile_selection a:nth-of-type(2).active ~ #profile_selection_slider { left: 275px; }
#profile_selection a:nth-of-type(3):hover ~ #profile_selection_slider, #profile_selection a:nth-of-type(3).active ~ #profile_selection_slider { left: 480px; }
对此
#profile_selection a:nth-of-type(1).active ~ #profile_selection_slider{ left: 71px; }
#profile_selection a:nth-of-type(2).active ~ #profile_selection_slider { left: 275px; }
#profile_selection a:nth-of-type(3).active ~ #profile_selection_slider { left: 480px; }
#profile_selection a:nth-of-type(1):hover ~ #profile_selection_slider{ left: 71px; }
#profile_selection a:nth-of-type(2):hover ~ #profile_selection_slider{ left: 275px; }
#profile_selection a:nth-of-type(3):hover ~ #profile_selection_slider{ left: 480px; }
所以即使其他 #profile_selection 是 .active
的,:hover 也可以工作http://jsfiddle.net/5DTKH/2/
相关文章:
- Javascript:selenium Web驱动程序isDisplayed()不工作
- 将PHP变量传递给jQuery时遇到问题
- jQuery UI自动完成突然停止工作
- AngularJS UI路由器不能像ng路由器那样工作
- HTML5音频加载和播放获胜'我不能在iPad上工作
- JavaScript打印功能使日历停止工作
- 我的jQuery插件参数没有正确启动,遇到了问题
- Javascript.getHours()工作不正常
- 我正试图获得一个带有复选框的多选下拉列表,在填充项目和获得所有选中的工作时遇到了一些问题
- 使 JavaScript 函数工作时遇到麻烦
- 在使 dojo 1.7.2 工作时遇到问题
- 让jQuery在Wordpress中工作时遇到麻烦
- JavaScript 或 CSS - 几乎可以工作,遇到一些障碍
- 后缀增量在JavaScript中遇到加法(+)运算符时是如何工作的
- 在字符串中遇到换行符时,Javascript无法在Visual Force页面上工作
- 在使表单javascript在foundation中工作时遇到问题
- 在让jquery进入工作的最后倒计时时遇到问题
- 让getJSON与codeigniter一起工作时遇到麻烦
- I'我在尝试将一个变量传递到一个已经工作的复杂正则表达式时遇到了问题
- 在PhantomJS中获得page.injectJs()工作时遇到麻烦