简体   繁体   English

将网络摄像头变成拉伸/缩放背景图像

[英]turning webcam into a stretching/scaling background image

connecting javascript to css div. 将JavaScript连接到CSS div。

I've given some javascript that drives a webcam some new functions such as a delay and to only display when its uploaded successfully for an art project. 我已经提供了一些Javascript,它们可以驱动网络摄像头一些新功能,例如延迟,并且仅在为艺术项目成功上传后才显示。

However I can no longer (for some stupid reason) connect it to my css without overriding the changes that i've made. 但是,我不能(出于某些愚蠢的原因)将其连接到CSS而不覆盖我所做的更改。 So that my simple web cam can be a background image that stretches to size on the page. 这样,我的简单网络摄像头就可以成为可以在页面上扩展到一定尺寸的背景图像。

(please see below) (请参阅下文)

I'd love to have the webcam background image be dynamically scaling but I don't think thats not possible in this context. 我希望网络摄像头的背景图像能够动态缩放,但我认为在这种情况下这是不可能的。

i'm sure you folks are more informed 我敢肯定你们的人更了解

EDIT: SORRY I WAS NOT CLEAR ENOUGH. 编辑:对不起,我还不够清楚。 So i want to have the webcam javascript seen below to be as a background image on my page. 所以我想让下面看到的网络摄像头javascript作为我页面上的背景图像。 i'm trying to make the webcam jpg turn into a background image. 我正在尝试将网络摄像头jpg转换为背景图像。 How ever i don't know how to connect the two with out over riding the changes i made. 我怎么不知道如何将两者联系起来,而不是依靠我所做的更改。

so if the javascript could be connected to the css example below which should turn it into a stretching background image. 因此,如果javascript可以连接到下面的css示例,则应将其转换为拉伸的背景图片。

  • it won't let me make the webcam connect to the css example shown. 它不会让我将网络摄像头连接到所示的CSS示例。 I can't understand how to get the css to all function.** 我不明白如何让CSS发挥所有功能。**

i hope that clears what i'm asking for. 我希望这能清除我的要求。

something to do with the reference to the element by its ID? 与通过元素ID引用元素有关?

EDIT: END 编辑:结束

 <script type="text/javascript">
$(document).ready(function(){

function reloadBackground() {
        var d = new Date().getTime();
        d -= 15; // delay
    url = "http://www.panopticbedroom.com/templates/live.jpg?" + d;
        var img = new Image();

        img.onload = function(){
              $('#divBackground ').html('').append($(this));
        }


        img.src = url;
}

setInterval(reloadBackground, 1000);

function getDocHeight() {
    var doc = document;
    return Math.max(
        Math.max(doc.body.scrollHeight, doc.documentElement.scrollHeight),
        Math.max(doc.body.offsetHeight, doc.documentElement.offsetHeight),
        Math.max(doc.body.clientHeight, doc.documentElement.clientHeight)
    );
}

});
</script>

and here is the relevant css: 这是相关的CSS:

#divBackground {
background-image: url(http://www.panopticbedroom.com/templates/live.jpg)
position: absolute;
}

img#imgBackground {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
}

I would really appreciate any advice! 我真的很感谢任何建议!

all the best, 祝一切顺利,

louis 路易斯

Use This Css Code to your img container 使用此CSS代码到img容器

background-attachment:fixed;
background-size:cover;
-webkit-background-size:cover;
-moz-background-size:cover;
-o-background-size:cover;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='source of image',sizingMethod='scale');
-ms-filter:"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='source of image', sizingMethod='scale')"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM