整页上的叠加画布(不仅仅是窗口)

时间:2017-01-20 19:16:02

标签: javascript html css html5 canvas

背景

我们以长页面格式呈现一些课程,每个部分都是窗口的全部高度...每节课中有许多不同的部分。

enter image description here

我想做什么 我希望人们能够遍布整个页面。正如您所看到的,有一些选项可以突出显示和删除画布内容。

这里的目标是让画布覆盖整个页面,以便用户可以随处绘制。

我尝试过的事情

我已将position:absolute添加到我的画布(#theCanvas)并将画布放在我的内容之上,但当我向下滚动时,我无法在初始窗口视口下绘制任何内容。

我的代码

标记

<canvas id="theCanvas"></canvas>

<div class="right-menu">

    <div class="right-menu-section">
        <div class="right-menu-section-circle">
            <svg height="32" width="32">
                <circle cx="16" cy="16" r="16" fill="#eeeeee">
            </svg>
        </div>
        <div class="right-menu-section-circle">
            <svg height="16" width="16">
                <circle cx="8" cy="8" r="8" fill="#eeeeee">
            </svg>
        </div>
        <div class="right-menu-section-circle">
            <svg height="8" width="8">
                <circle cx="4" cy="4" r="4" fill="#eeeeee">
            </svg>
        </div>
    </div>

    <div class="right-menu-section">
        <div class="right-menu-section-icon">
            <i class="fa fa-eraser" aria-hidden="true"></i>
        </div>
        <div class="right-menu-section-icon">
            <i class="fa fa-pencil" aria-hidden="true"></i>
        </div>
        <div class="right-menu-section-icon">
            <i class="fa fa-hand-pointer-o" aria-hidden="true"></i>
        </div>
    </div>

    <div class="right-menu-section">
        <div id="colors"></div>
    </div>

    <div class="right-menu-section">
        <div class="right-menu-section-icon">
            <i class="fa fa-hand-paper-o" aria-hidden="true"></i>
        </div>
    </div>

</div>

<div class="" style="display:block;position:absolute;float:right;margin-left:40px;margin-top:20px">
    <h4>Estimated Time to complete:<h4>
    <h2>
        <i class="fa fa-clock-o"></i>
        25m
    </h2>
</div>

<!-- intro -->
<div class="container-fluid card" style="background:#e8e6e1">
    <div class="container card-content">
        <h1 class="text-center">Welcome...</h1>
        <h4 class="text-center">
            Today's Lesson Focus:
            <?php echo $focus->lesson_focus; ?>
        </h4>
        <p class="text-center"><b>Details:</b> <?php echo $focus->details; ?></p>
    </div>
</div>
<!-- end intro -->

<!-- lesson -->
<?php foreach ($cards as $card) : ?>
<div class="container-fluid card" style="background:#eaeaec">
    <div class="container card-content">
        <div class="col-md-6">
            <h2>
                <?php echo $card->card_title; ?>
                <i class="fa fa-volume-up"></i>
            </h2>
            <p><?php echo $card->card_content; ?></p>
        </div>
        <div class="col-md-6">
            <img src="<?php echo $card->card_file_path; ?>" alt="">
        </div>
    </div>
</div>
<?php endforeach; ?>
<!-- end lesson -->

<!-- outtro -->
<div class="container-fluid card" style="background:#E7E1E8">
    <h1 class="text-center">Thanks!</h1>
</div>
<!-- end outtro -->

CSS

.card {
        height: 100vh;
        display: flex;
        justify-content: center;
        align-items: center;
        margin-right:50px;
    }

    .card-content {

    }

    .card-content img {
        width:100% !important;
        -webkit-box-shadow: 0px 0px 71px -11px rgba(0,0,0,0.75);
        -moz-box-shadow: 0px 0px 71px -11px rgba(0,0,0,0.75);
        box-shadow: 0px 0px 71px -11px rgba(0,0,0,0.75);
        border-radius: 20px;
    }

    .right-menu {
        position:fixed;
        float:right;
        height:100vh;
        right: 0;
        top: 0;
        width:50px;
        background:#222222;
        -webkit-box-shadow: -4px 0px 10px 0px rgba(153,153,153,1);
        -moz-box-shadow: -4px 0px 10px 0px rgba(153,153,153,1);
        box-shadow: -4px 0px 10px 0px rgba(153,153,153,1);
        border-top:1px solid #444444;
    }

    .right-menu-section {
        border-top:1px solid #444444;
        padding-top:20px;
        padding-bottom:20px;
    }

    .right-menu-section-icon {
        color: #eeeeee;
        margin-top:10px;
        font-size:24px;
        display:block;
        text-align:center;
    }

    .right-menu-section-circle {
        color: #eeeeee;
        margin-top:10px;
        display:block;
        text-align:center;
    }

    .swatch {
        width:30px;
        height:30px;
        border-radius:15px;
        box-shadow: inset 0px 1px 0px rgba(255, 255, 255, 0.5), 0px 2px 2px rgba(0, 0, 0, 0.5);
        display: block;
        margin-top: 10px;
        margin-left:10px;
    }

    #theCanvas {
        position: absolute;
    }

我的问题

如何让画布跨越整个页面,而不仅仅是窗口。

2 个答案:

答案 0 :(得分:1)

将此CSS用于画布:

#theCanvas{
  position:fixed;
  top:0;
  right:0;
  bottom:0;
  left:0;
}

具有固定位置的元素保持在相同的位置,以相对于视口的顶部/右侧/底部/左侧值给出,因此即使滚动也会保持在整个页面上的分布。

答案 1 :(得分:1)

尝试添加此css:

html {
    height:100%;
}

body { 
     min-height:100%;
}

#theCanvas {
     min-height:100%;
}