Home  >  Article  >  Web Front-end  >  "Select/drag-and-drop functionality in HTML5 Canvas and JS libraries?"

"Select/drag-and-drop functionality in HTML5 Canvas and JS libraries?"

WBOY
WBOYforward
2023-09-02 11:13:021104browse

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

If you want to use HTML5 canvas to draw shapes, text and curves, and also want to attach traditional DOM events such as onClick or drag and drop functionality, you can use the Crossbar framework Raphael To perform drag and drop operations drop or touch events.

This technique uses SVG and XML for older versions of IE. Drag and drop using HTML is shown below.

Example

<!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>

The above is the detailed content of "Select/drag-and-drop functionality in HTML5 Canvas and JS libraries?". For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete