[英]Adding image to a div using JQuery
I'm trying to create a poker web app using an poker library ( http://tairraos.github.io/Poker.JS/ ) 我正在尝试使用扑克库( http://tairraos.github.io/Poker.JS/ )创建一个扑克网络应用程序
One of the methods to render a card image is using this function: 渲染卡片图像的一种方法是使用此功能:
getCardImage: function(size, suit, point) {
var image = document.createElement('img');
image.src = this.getCardData(size, suit, point);
return image;
},
It creates an image using canvas and places inside an img tag. 它使用画布创建图像并将其放置在img标签内。 I've been trying to place it inside a div, like:
我一直试图将其放在div中,例如:
$('#flop').append(Poker.getCardImage(60, 'hearts', 'j'));
but to no avail. 但无济于事。 The only way it renders normally is using:
它正常呈现的唯一方法是使用:
document.body.appendChild(Poker.getCardImage(100, 'h', 'Q'));
I really run off of ideas of how to pull this out. 我真的没有想到如何实现这一目标。 I've tried many JQuery methods and nothing worked.
我尝试了许多JQuery方法,但没有任何效果。 I see on the network tab of chrome that the image is created using a base64, but when I try to place it inside a div, nothing appears.
我在chrome的网络标签上看到该图片是使用base64创建的,但是当我尝试将其放置在div中时,什么也没有出现。 Only if appends to the end of the body.
只有附加到主体的末端。 Can someone lend me a help here?
有人可以在这里帮我吗?
tnx n
I think you should just have to change your getCardImage
function to return a jQuery Element instead of an HTML element. 我认为您只需要更改
getCardImage
函数即可返回jQuery元素而不是HTML元素。 Try this: 尝试这个:
getCardImage: function(size, suit, point) {
var image = '<img src="' + this.getCardData(size, suit, point) + '" />';
return $(image);
}
Then your jQuery append should work: 然后您的jQuery附加文件应该可以工作:
$('#flop').append(Poker.getCardImage(60, 'hearts', 'j'));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.