Skip to content Skip to sidebar Skip to footer

Hide Svg Elements With Javascript

I'm trying to make a javascript vector animation with SVG. At the start, there is a play button. When this is pressed, it starts the music and should hide itself. This is my HTML:

Solution 1:

Use detach instead - it removes the element from the dom but keeps the reference.

var playButton = $('#play-button');

functionstart() {

    try {
        $('audio').currentTime=0;
    }
    catch(e) {} 
    $('audio').play();

    playButton.detach();
}

//re-add playbutton
$('#canvas').append(playButton);

Solution 2:

Set opacity in css for hide svg elements

 $('#play-button').css({"opacity": 0 });

Link

Solution 3:

Try to work with the SVG document itself:

var obj = $('#canvas').get(0);

obj.onload = function() {
  var doc = obj.contentDocument;

  doc.find('#play-button').click(function() {
    $(this).fadeTo(400, 0);
  });
};

Post a Comment for "Hide Svg Elements With Javascript"