【问题标题】:removeAttr("style") and attr("style","") not workingremoveAttr("style") 和 attr("style","") 不起作用
【发布时间】:2012-11-28 11:54:52
【问题描述】:

http://synergine.net/rain.php

你好。我正在尝试清除 .ripple div 中所有元素的样式属性,但未成功:

function contact(level){
focus_ripple = Math.floor(Math.random() * 100) + 1;
$("#"+level+" .ripple"+focus_ripple+" p").css("opacity",1);
$("#"+level+" .ripple"+focus_ripple+" .fourth").animate({
    height: "324px",
    width: "324px",
    top: "-162px",
    left: "-162px",
    "border-radius": "162px"
},{duration: 1000, queue: false});
$("#"+level+" .ripple"+focus_ripple+" .third").animate({
    height: "108px",
    width: "108px",
    top: "-54px",
    left: "-54px",
    "border-radius": "54px"
},{duration: 1000, queue: false});
$("#"+level+" .ripple"+focus_ripple+" .second").animate({
    height: "32px",
    width: "32px",
    top: "-18px",
    left: "-18px",
    "border-radius": "18px"
},{duration: 1000, queue: false});
$("#"+level+" .ripple"+focus_ripple+" .first").animate({
    height: "10px",
    width: "10px",
    top: "-6px",
    left: "-6px",
    "border-radius": "6px"
},{duration: 1000, queue: false});
$("#"+level+" .ripple"+focus_ripple+" p").animate({
    opacity: 0
},{duration: 1550, queue: false});
setTimeout(function() {
    $("#"+level+" .ripple"+focus_ripple+" p").removeAttr("style");
},1575);
counter++;

}

非常感谢您对此的任何帮助。谢谢。

【问题讨论】:

  • 这是一个已知错误:bugs.jquery.com/ticket/9699 - 您使用的是什么版本的 jQuery 和浏览器?
  • 我也试过在 settimeout 函数中设置样式。动画到不透明度后没有任何效果:0

标签: jquery attr


【解决方案1】:

removeAttr() 在 1.7.2 上为我工作:

$("div").click(function(){
    $(this).removeAttr("style");
})​

见小提琴:http://jsfiddle.net/adrianonantua/p5Dcs/

你必须确保你的选择器确实带来了结果。

【讨论】:

  • 绝对。 removeAttr 通常也适用于我。只是无法弄清楚我发布的代码末尾的绊脚石是什么(在动画到不透明度:0 后没有任何工作)。
猜你喜欢
  • 1970-01-01
  • 2015-01-24
  • 1970-01-01
  • 1970-01-01
  • 2018-03-19
  • 2013-09-24
  • 2018-02-04
  • 2018-09-30
  • 1970-01-01
相关资源
最近更新 更多