繁体   English   中英

将photoslider放在画布标签内

[英]Put a photoslider inside canvas tag

我正在尝试在html5中创建一个photoslider,然后将其放在canvas标记中。 到目前为止,我可以看到图像,但是无法将画布放在它们后面。 有人可以告诉我发生了什么吗? 先感谢您。

HTML:

<html>
<head>
    <script type="text/javascript">
        var step = 1;
        var img = new Array(17);

        for(var i = 1; i <= 17; i++){
            img[i] = new Image();
            img[i].src = "/images/img"+i+".jpg";    //load images
        }
    </script>

    <script type="text/javascript" src="\js\photoSliderController.js"></script>
</head>
<body>
<section id="photoSliderContainer">
        <img name="slide" id="photoSliderControls" src="C:\Users\Vassileios\Dropbox\symmetexw\images\img1.jpg" width="500" height="300"> 
            <script type="text/javascript">
                slideImages();
            </script>
        </img>
        <canvas id="photoSliderViewport">
            Your browser does not support the HTML5 canvas tag.
        </canvas>
    </section>
</body>
</html>

CSS:

#photoSliderViewPort{
float: right;
margin-top: 3%;
margin-right: 0%;
margin-bottom: 95%;
margin-left: 24%;
width: 800px;
height: 800px;
background:rgba(75,75,186,1);
}

#photoSliderControls{
float: right;
margin-top: 3%;
margin-right: 0%;
margin-bottom: 95%;
margin-left: 24%;
z-index:1;
}

JS:

function slideImages(){
document.images.slide.src = eval("img["+step+"].src");
    if(step<17)
        step++;
    else
        step=1;
setTimeout("slideImages()",3000);
}

 var canvas = document.getElementById('photoSliderViewport'); var ctx = canvas.getContext('2d'); var step = 0; // Start Array key (0 indexed) var images = []; // Array of image paths var nOfImages = 5; // Set here the desired number of images canvas.width = 800; canvas.height = 800; // Populate array with paths; for(var i=1; i<=nOfImages; i++){ images.push("http://placehold.it/800x800/ccc&text="+i+".jpg"); } console.log(images); function slideImages(){ var img = new Image(); img.onload = function(){ // Once it's loaded... ctx.drawImage(img, 0, 0); // Draw it to canvas step = ++step % nOfImages ; // Increase and loop step setTimeout(slideImages, 3000); // Do it again in 3000ms }; img.src = images[step]; // Finally, set the new image src } slideImages(); // START 
  <section id="photoSliderContainer"> <canvas id="photoSliderViewport"> Your browser does not support the HTML5 canvas tag. </canvas> </section> 

暂无
暂无

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

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