jQuery - 如何在将此元素添加到DOM后添加css或隐藏元素

时间:2016-03-26 04:22:09

标签: javascript jquery html5 canvas

我有一个标题问题,我希望在将此元素添加到DOM后添加css或隐藏元素。   - 我知道一种在使用jquery创建元素时添加属性的方法:

$('body').on('click','#newElement',function() {})

但必须单击newElement才能执行此功能。

<script>
var h_notepad = 500;
var w_notepad = 737;
var data = [
  {dataImageURL: "1_sat_1.png", hide_canvas : 0},
  {dataImageURL: "1_sat_2.png", hide_canvas : 0},
  {dataImageURL: "1_sat_3.png", hide_canvas : 1},
  {dataImageURL: "1_sat_4.png", hide_canvas : 0}
];
for(var i = 0; i < data.length ; i++){

  var img = new Image();
  img.crossOrigin = 'anonymous';
  img.onload = function(){
    var canvas = document.createElement('canvas');
    canvas.width = w_notepad;
    canvas.height = h_notepad;
    $('body').append(canvas);	
    //how to hide and AddClass for canvas ?
    var ctx = canvas.getContext('2d');
    ctx.drawImage(this, 0, 0, w_notepad, h_notepad);
  };
  img.src = data[i].dataImageURL;
//how to hide and addClass for canvas with data[i].hide_cavas after canvas has been added to DOM?		
		}
</script>
<html>
<head>
<meta charset="utf-8">
<title>DRAWING</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<meta charset="utf-8">

</head>
<body>
	

</body>
</html>

谢谢。

0 个答案:

没有答案