简体   繁体   English

如何修复与可拖动 canvas 的碰撞?

[英]How do I fix a collision with a draggable canvas?

I am making a module for a cmyk color model.我正在为 cmyk 颜色 model 制作一个模块。 It's a simple program, but I need advice or solution on how to do it so that the balls are not draggable even outside the background.这是一个简单的程序,但我需要有关如何执行此操作的建议或解决方案,以便即使在背景之外也无法拖动球。 How should I do that?我该怎么做?

My Code:我的代码:

<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css">
    <link rel="stylesheet" href="{{ url_for('static', filename='modules/CMYK/style.css') }}">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
    <script>
        $(function(){
            $(".circle").draggable();
        })
    </script>

    <div class="background">
        <div class="circle color-circle-light cr-red"></div>
        <div class="circle color-circle-light cr-green"></div>
        <div class="circle color-circle-light cr-yellow"></div>
    </div>

You are looking for containment: "parent" .您正在寻找containment: "parent"

 $(function() { $(".circle").draggable({ containment: "parent" }); })
 <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script> <div class="background"> <div class="circle color-circle-light cr-red">Div1</div> <div class="circle color-circle-light cr-green">Div2</div> <div class="circle color-circle-light cr-yellow">Div3</div> </div>

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

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