Is there a cross-browser way to ignore opacity when using jquery clone ()?

I use tables in my document, and I want the user to be able to send a new item to the list, and then "automatically" appear at the top of the list (yes, that would be easier with the DIV, but working with what I have) .

I use jQuery clone()to create a copy of the last row of the table, and then use fadeIn()to display a new item after updating and adding it to the top of the list. Since internally jQuery converts the elements (assuming a DIV) to "block", I also change the css class to "table-row". It works great.

All code is here:

    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"); 

The problem is that if I started the process too fast - that is, before fadeIn is completed, the clone () command also clones the opacity.

I can get it working in Firefox using the first line setting above:

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

Now I'm worried that I'm not sure that all this is being done efficiently and / or that "opacity" is a cross-browser that you can rely on.

Has anyone done something similar before and can offer any pointers to a more robust approach?

+3
source share
3 answers

opacity as a jQuery css attribute is a safe cross-browser because it conceals browser differences in implementation. Here is the source

// 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) + '': "";
}

. - /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");
+2

. dom, .

:

var row = $("tbody tr:first").clone(); // clone
// set some properties
row.children("td[class=td-date]").html("today");
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").fadeOut(0).fadeIn(2000).css("display","table-row");
+1

I think jQuery will handle this if you do this.

var row = $("tbody tr:first").clone().fadeIn(0).hide();
0
source

Source: https://habr.com/ru/post/1715747/


All Articles