Saturday, November 15, 2025
HomeLanguagesJavascriptscript.aculo.us Drag & Drop hoverclass Option

script.aculo.us Drag & Drop hoverclass Option

This script.aculo.us Drag & Drop hoverclass Option is used create a active hoverclass where you can drag a drag-able element to a drop area. In that drop area, the element will be placed. This is a name of a CSS class which will be added to an element while the droppable option is active.

Syntax:

Droppables.add('element', {hoverclass: 'cssClass'});

Example: Below example illustrate the script.aculo.us Drag & Drop hoverclass Option.




<!DOCTYPE html>
<html>
  
<head>
    <script type="text/javascript" 
        src="scriptaculous-js-1.9.0/lib/prototype.js">
    </script>
  
    <script type="text/javascript" 
        src="scriptaculous-js-1.9.0/src/scriptaculous.js">
    </script>
      
    <script type="text/javascript">
        window.onload = function () {
            $A($("draggables").getElementsByTagName(
                "img")).each(function (item) {
                    new Draggable(
                        item, { revert: true, ghosting: true });
                });
  
            Droppables.add(
                "droparea", {
                    hoverclass: "hoverActive",
                onDrop: moveItem
            });
  
            // Set drop area default non cleared.
            $("droparea").cleared = false;
        };
  
        function moveItem(draggable, droparea) {
            if (!droparea.cleared) {
                droparea.innerHTML = "";
                droparea.cleared = true;
            }
  
            draggable.parentNode.removeChild(draggable);
            droparea.appendChild(draggable);
        }
    </script>
  
    <style type="text/css">
        #draggables {
            width: 550px;
            height: 73px;
        }
  
        #droparea {
            float: left;
            width: 550px;
            height: 73px;
            border: 2px solid gray;
            text-align: center;
            font-size: 16px;
            padding: 12px;
        }
    </style>
</head>
  
<body>
    <div>
        <h1 style="color: green;">neveropen</h1>
  
        <p>A Computer Science Portal for Geeks</p>
  
    </div>
    <strong>
        script.aculo.us Drag & Drop hoverclass Option
    </strong>
    <div id="draggables">
        <img src="gfg.png" />
    </div>
    <div id="droparea">
        Drag the Image and Drop Your Image in this area
    </div>
</body>
  
</html>


RELATED ARTICLES

Most Popular

Dominic
32399 POSTS0 COMMENTS
Milvus
95 POSTS0 COMMENTS
Nango Kala
6765 POSTS0 COMMENTS
Nicole Veronica
11917 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11984 POSTS0 COMMENTS
Shaida Kate Naidoo
6890 POSTS0 COMMENTS
Ted Musemwa
7143 POSTS0 COMMENTS
Thapelo Manthata
6838 POSTS0 COMMENTS
Umr Jansen
6840 POSTS0 COMMENTS