'HTML5 Canvas和JS库中的选择/拖放功能?'

WBOY
发布: 2023-09-02 11:13:02
转载
1084 人浏览过

"HTML5 Canvas和JS库中的选择/拖放功能?"

如果你想使用 HTML5 canvas 来绘制形状、文本和曲线,并且还想附加传统的 DOM 事件,如 onClick 或拖放功能,可以使用 Crossbar 框架 Raphael 来进行拖放操作放下或触摸事件。

此技术针对旧版本的 IE 使用 SVG 和 XML。使用 HTML 进行拖拽如下所示。

示例

<!DOCTYPE html>
<html lang = "en">
   <head>
      <meta charset = "utf-8">
         <title>Rapha&euml;l &middot; Drag-n-drop</title>
         <link rel = "stylesheet" href = "demo.css" type = "text/css" media = "screen">
         <meta name = "apple-mobile-web-app-capable" content = "yes">
         <link rel = "apple-touch-icon-precomposed" href = "/Raphael.png">
         <link rel = "stylesheet" href = "demo-print.css" type = "text/css" media = "print">
         <script src = "raphael.js"></script>
         <script>
            window.onload = function () {
               var R = Raphael(0, 0, "100%", "100%"),
               r = R.circle(100, 100, 50).attr({fill: "hsb(0, 1, 1)", stroke: "none", opacity: .5}),
               g = R.circle(210, 100, 50).attr({fill: "hsb(.3, 1, 1)", stroke: "none", opacity: .5}),
               b = R.circle(320, 100, 50).attr({fill: "hsb(.6, 1, 1)", stroke: "none", opacity: .5}),
               p = R.circle(430, 100, 50).attr({fill: "hsb(.8, 1, 1)", stroke: "none", opacity: .5});
            var start = function () {
               this.ox = this.attr("cx");
               this.oy = this.attr("cy");
               this.animate({r: 70, opacity: .25}, 500, ">");
            },
            move = function (dx, dy) {
               this.attr({cx: this.ox + dx, cy: this.oy + dy});
            },
            up = function () {
               this.animate({r: 50, opacity: .5}, 500, ">");
            };
            R.set(r, g, b, p).drag(move, start, up);
         };
      </script>
   </head>
   <body>
      <div id = "holder"></div>
      <p id = "copy">Demo of <a href = "http://raphaeljs.com/">Rapha&euml;l</a>&mdash; JavaScript Vector Library</p>
   </body>
</html>
登录后复制

以上是'HTML5 Canvas和JS库中的选择/拖放功能?'的详细内容。更多信息请关注PHP中文网其他相关文章!

来源:tutorialspoint.com
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!