jQuery CSS背景位置 [英] jquery css background-position

查看:66
本文介绍了jQuery CSS背景位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的-我正在尝试将jquery插件用于iPhone切换.但是IE在显示背景图像时出现了问题.

这是引起麻烦的代码-

okay - I am trying to make use of jquery plugin for iphone switch. But IE is giving problem in displaying the background image.

Here is the code that''s causing trouble -

image = jQuery('<img class="iphone_switch" style="height:'+settings.switch_height+'px; width:'+settings.switch_width+'px; background-image:url('+settings.switch_path+'); background-repeat:none; background-position:'+(state == 'on' ? 0 : -53)+'px" src="'+(state == 'on' ? settings.switch_on_container_path : settings.switch_off_container_path)+'" />');



当我从上面的代码中删除



when I remove

background-position:'+(state == 'on' ? 0 : -53)+'px"

时,我可以看到ON/OFF背景IE上的图片,但是一旦我单击按钮,它便再次消失.

这是点击功能-

from above code - then I can see ON/OFF background image on IE but as soon as i click the button, it''s again disappeared.

Here is the click function -

jQuery(this).click(function() {
			if(state == 'on') {
				jQuery(this).find('.iphone_switch').animate({backgroundPosition: -53}, "slow", function() {
					jQuery(this).attr('src', settings.switch_off_container_path);
					switched_off_callback();
				});
				state = 'off';
			}
			else {
				jQuery(this).find('.iphone_switch').animate({backgroundPosition: 0}, "slow", function() {
					switched_on_callback();
				});
				jQuery(this).find('.iphone_switch').attr('src', settings.switch_on_container_path);
				state = 'on';
			}
		});		



有什么建议吗?

谢谢



Any suggestions?

Thanks

推荐答案

I faced the same problem with IE8.. Finally got time to resolve it today.

On line 37 where an image element is being created.. instead of using a closing tag ix it and it will work

have fun.


这篇关于jQuery CSS背景位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆