[英].removeAttr('style') doesn't seem to work as expected on ipad
Do anyone know why the CSS doesn't update on ipad if you use .removeAttr('style')
? 如果你使用
.removeAttr('style')
有谁知道为什么CSS不会在ipad上更新?
Here's a quick example to show how I implemented my sprite switching: 这是一个快速示例,展示我如何实现我的精灵切换:
CSS CSS
nav li a { background: url('../img/sprites.gif'); }
nav li a#pizza { background-position: -40px -42px; }
nav li a#beer { background-position: -40px -82px; }
nav li a#spagetti { background-position: -40px -122px; }
Javascript 使用Javascript
var $arr_nav_elements = $('nav li a');
$('nav li a').on('click', function(event) {
//works fine on all modern browsers except ipad!
$arr_nav_elements.removeAttr('style');
var $arr_bg_pos = $(this).css('backgroundPosition').split(" ");
//create "active" state on the current button
$(this).css('backgroundPosition', '0 '+$arr_bg_pos[1]);
}
In the example above my button will change to the "active" state in my sprites.gif at first click, however the inline style applied by jQuery's css() won't be removed/updated on ipad after I click on any different buttons. 在上面的例子中,我的按钮将在第一次点击时在我的sprites.gif中变为“活动”状态,但是点击任何不同的按钮后,jQuery的css()应用的内联样式将不会在ipad上删除/更新。
Any ideas? 有任何想法吗?
Seems as if .removeAttr('style');
好像
.removeAttr('style');
has some issues on ipad (prob. all ios devices) 在ipad上有一些问题(概率所有ios设备)
As pointed out by A. Wolff and ᾠῗᵲᄐᶌ these alternatives work fine: 正如A. Wolff和ᾠῗᵲᾠῗᵲᄐ指出的那样,这些替代方案工作得很好:
.attr('style','');
.css('backgroundPosition','');
hope this helps: 希望这可以帮助:
try something like this: 尝试这样的事情:
//replace the $.each(...) block with following
$('nav li a').each(function(){
$(this).css('name','value'); //here you manually adjust your css styles
});
good luck in your project! 祝你的项目好运!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.