[英]JQuery not removing background image if .active class
我在使用jQuery时遇到麻烦,无法删除背景图片。
我正在使用具有深层链接的Zurb的Foundation框架 ,并以这种形式编写了一些代码(我砍掉了很多html):
<div id="contentWrap">
<section id="one" class="mixed">
<a href="#">One</a>
<div class="content"></div>
</section>
<section id="two" class="mixed active">
<a href="#">One</a>
<div class="content"></div>
</section>
</div>
我正在使用CSS设置#contentWrap与背景图像,但我只希望在第一个链接处于活动状态时显示该图像。
我正在使用此JQuery代码:
// Add background image if #one clicked
$('#one a').click(function(){
$("#contentWrap").css("background-image","url('xx.jpg')");
});
// Remove background image if #two clicked
$('#two a').click(function(){
$("#contentWrap").css("background-image","none");
});
// Remove background image if #two has class of .active
if ( $("#two").hasClass("active") ) {
$("#contentWrap").css("background-image","none")
};
如果通过深链接(即xx.com/#two)在页面上加载了第二个选项卡,则背景图像仍会加载。
我曾经有过这个工作,但是自那以后对代码在(wordpress)网站上的加载方式进行了几次更新,现在正在使用jQuery(document).ready(function($)
来包装所有其他JS(正在工作) )。
任何帮助,不胜感激。
如果我说对了,那么当two
div处于活动状态时,仅应删除背景?
// Remove background image if #two clicked
$('#two a').click(function(){
// Remove background image if #two has class of .active
if ( $("#two").hasClass("active") ) {
$("#contentWrap").css("background-image","none")
};
});
工作jsfiddle:(将background-image
更改为background
) http://jsfiddle.net/Vvg5F/4/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.