简体   繁体   English

带背景图片问题的切换类

[英]toggleclass with background-image issue

i have a div with an id that i want to use for switchin between 2 classes. 我有一个div,我想将其ID用于2个类之间的切换。 the purpose is to change class when i click showing a different background-image (inside, infact, in the second class). 目的是当我单击显示不同的背景图像(实际上是第二类时)时更改类。 the div comes with a class default div带有一个类默认值

 <a href="#"><div id="equipment" class="flash"> </div></a>

this is the css 这是CSS

 #equipment {

float: right;
margin-right: 30px;
width: 55px;
height: 81px;

 }
   .flash {


background: url('equipment.jpg');
background-size: 55px 81px;
background-repeat: no-repeat;
     }


.flashOn {



background: url ('equipment3.jpg')  no-repeat scroll;
background-size: 55px 81px;

font-size: 20px;


     }

and this is the simple jquery 这是简单的jQuery

 $('#equipment').click(function(){

 $('#equipment').toggleClass('flashOn');

 }); 

i tested and the toggleClass work partially. 我测试和toggleClass部分工作。 as the font size change.. but it doesnt change the background image in the div. 随着字体大小的变化..但它不会改变div中的背景图像。 Any clue? 有什么线索吗? thanks in advance., Paolo 在此先感谢。,Paolo

change 更改

$('#equipment').click(function(){

 $('#equipment').toggleClass('flashOn');

 });

to

    $('#equipment').click(function(){

 $('#equipment').toggleClass('flashOn flash');

 }); 

http://jsfiddle.net/osmanrahimi/xwnKP/215/ http://jsfiddle.net/osmanrahimi/xwnKP/215/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM