gpt4 book ai didi

javascript - 使用 jquery 的 clone() 时,是否有跨浏览器的方法来忽略不透明度?

转载 作者:行者123 更新时间:2023-11-29 10:55:00 25 4
gpt4 key购买 nike

我在我的文档中使用表格,我希望能够让用户向列表提交一个新项目,然后让它“自动”出现在列表顶部(是的,这会更容易使用 DIV,但使用我所拥有的)。

我正在使用 jQuery 和 clone() 创建最新表格行的副本,然后使用 fadeIn() 在我之后显示新项目更新并将其添加到列表的顶部。因为 jQuery 在内部将元素(假设为 DIV)转换为“ block ”,所以我还将 css 类更改为“table-row”。它工作正常。

完整代码在这里:

    var row = $("tbody tr:first").clone().hide(); // clone and then set display:none
row.children("td[class=td-date]").html("today");
// set some properties
row.children("td[class=td-data]").html("data");
row.children("td[class=td-type]").html("type");
// fadeIn new row at the top of the table.
row.insertBefore("tbody tr:first").stop().fadeIn(2000).css("display","table-row");

问题是如果我运行过程太快 - 即在 fadeIn 完成之前,“clone()”命令最终也会克隆不透明度。

我实际上可以通过调整上面的第一行来让它在 Firefox 中工作:

 var row = $("tbody tr:first").clone().css("opacity","1").hide();

我现在担心的是,我不确定这些是否有效地完成,和/或“不透明度”是否可以跨浏览器安全地依赖。

有没有人以前做过这样的事情,并且可以提供任何关于更可靠方法的指示?

最佳答案

opacity 作为 jQuery css 属性是安全的跨浏览器,因为它消除了浏览器在实现中的差异。这是来源

// IE uses filters for opacity
if ( !jQuery.support.opacity && name == "opacity" ) {
if ( set ) {
// IE has trouble with opacity if it does not have layout
// Force it by setting the zoom level
elem.zoom = 1;

// Set the alpha filter to set the opacity
elem.filter = (elem.filter || "").replace( /alpha\([^)]*\)/, "" ) +
(parseInt( value ) + '' == "NaN" ? "" : "alpha(opacity=" + value * 100 + ")");
}

return elem.filter && elem.filter.indexOf("opacity=") >= 0 ?
(parseFloat( elem.filter.match(/opacity=([^)]*)/)[1] ) / 100) + '': "";
}

以下作品。 Working Demo - 将 /edit 添加到 URL 以使用它。

  // stop previous animation on the previous inserted element
var prevRow = $("tbody tr:first").stop(true,true);

var row = prevRow.clone();
row.children("td.td-date").text("today");
row.children("td.td-data").text("data");
row.children("td.td-type").text("type");

row.fadeIn(2000).prependTo("tbody");

关于javascript - 使用 jquery 的 clone() 时,是否有跨浏览器的方法来忽略不透明度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1314669/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com