Guide on moving a single item from one div to another

Here is a div that I need to modify:

<div class="npwfu-inspiration">
    <div class="npwfu-inspiration-inner">
        <h1>Looking for inspiration?</h1>

        <p>Pick a category to see examples of what you can create with Spark.</p>
        <ul class="inspiration-category-list"></ul>
    </div>
</div>
<div class="div2"></div>

I want to move the "inspiration-category-list" ul into another div called "div2" using CSS transition. It should slide down and stay positioned 80px from the top within "div2".

Can anyone help me achieve this effect using jQuery?

Answer №1

Have you considered using drag effect instead of CSS transition?
If you are interested, you can implement draggable functionality to any element you wish to move by utilizing dragable.js from the provided link. In your JavaScript code, simply set $

(".inspiration-category-list").draggable ()

Rather than relying on CSS transitions, you can smoothly drag and drop the elements into any desired div container.

/*--------------------------------------------------------------
Draggable
An alternative to jQuery UI’s draggable functionality
Based on comments from: http://css-tricks.com/snippets/jquery/draggable-without-jquery-ui/
Usage example: $('.post-thumbnail, article header').draggable();
--------------------------------------------------------------*/
(function ($) {
    if (!jQuery().draggable) {
        $.fn.draggable = function () {
            var _fixMobileEvent = function (e) {
                if (e.originalEvent && e.originalEvent.targetTouches && e.originalEvent.targetTouches[0]) {
                    var t = e.originalEvent.targetTouches[0];
                    e.pageX = t.clientX;
                    e.pageY = t.clientY;
                    return true;
                } else {
                    return false;
                }
            };
            this
                .css('cursor', 'move')
                .on('mousedown touchstart', function (e) {
                    _fixMobileEvent(e);
                    var $dragged = $(this);

                    var startOffset = $dragged.offset();
                    var x = startOffset.left - e.pageX,
                        y = startOffset.top - e.pageY,
                        z = $dragged.css('z-index');

                    if (!$.fn.draggable.stack) {
                        $.fn.draggable.stack = 999;
                    }
                    stack = $.fn.draggable.stack;
                    var firstMove = true;
                    var $preventClick = null;

                    $(window)
                        .on('mousemove.draggable touchmove.draggable', function (e) {
                            _fixMobileEvent(e);

                            if (firstMove) {
                                firstMove = false;
                                $dragged
                                    .css({
                                        'z-index': stack, 'transform': 'scale(1.1)', 'transition': 'transform .3s',
                                        'bottom': 'auto', 'right': 'auto'
                                    });

                                var $target = $(e.target);
                                if ($target.is('a')) {
                                    $preventClick = $target;
                                    $target.one('click.draggable', function (e) {
                                        e.preventDefault();
                                        e.stopImmediatePropagation();
                                    });
                                } else if ($dragged.is('a')) {
                                    $preventClick = $dragged;
                                    $dragged.one('click.draggable', function (e) {
                                        e.preventDefault();
                                        e.stopImmediatePropagation();
                                    });
                                }
                            }
                            $dragged.offset({
                                left: x + e.pageX,
                                top: y + e.pageY
                            });
                            e.preventDefault();
                        })
                        .one('mouseup touchend touchcancel', function () {
                            $(this).off('mousemove.draggable touchmove.draggable');
                            $dragged.css({ 'z-index': z, 'transform': 'scale(1)' })
                            $.fn.draggable.stack++;

                            if (_fixMobileEvent(e)) {
                                if ($preventClick) $preventClick.off('click.draggable');
                                var endOffset = $dragged.offset();

                                if (Math.abs(endOffset.left - startOffset.left) <= 3
                                        && Math.abs(endOffset.top - startOffset.top) <= 3) {

                                    if ($preventClick) {
                                        $preventClick[0].click();
                                    } else {
                                        var $target = $(e.target);
                                        if ($target.is('a')) {
                                            e.target.click();
                                        } else if ($dragged.is('a')) {
                                            $dragged[0].click();
                                        }
                                    }
                                }
                            }
                        });

                    e.preventDefault();
                });
            return this;
        };
    }
})(jQuery);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The Jquery ajax function is functional on a local environment, but fails to work when

Can someone please help me with this issue? I've been trying all day to figure it out, but I can't seem to... So, I have this function: function doSearch(){ $('#dg').datagrid('load',{ search: $('#sea ...

Is it possible to integrate Processing JS on top of an HTML element?

I have currently integrated Processing JS with the HTML canvas element on a website. The goal is to have the Processing JS animation run smoothly over the existing HTML elements on the page. You can check out the site at [usandthings.com][1] to get an idea ...

Exploring the functionalities of the execPopulate() method

I'm hitting a roadblock with using execPopulate. I've gone through the documentation, but it's just not clicking for me. Could someone clarify when exactly execPopulate() should be used after populate() and when it's unnecessary? In s ...

Is it possible to redirect any web traffic using an authentication script?

Scenario: I'm currently working on a social networking project and I'm looking for a way to validate every redirect or refresh by directing the user through another script before reaching their final destination. I've considered using a &apo ...

When an ajax post is in progress, jQuery blocks functions from running

Is there a way to prevent all functions from executing while an ajax post is in progress? For instance, let's say I have a modal box with two forms that can be switched between using a tab navigation. When a user submits one of the forms, the data is ...

How to trigger a submit action on a different page from an iframe using PHP

Is there a way to submit the iframe page using the modal's submit button in Page1.php to trigger the submit button of Page2.php? I need help executing this efficiently. The purpose of having the submit button in a modal is to perform multiple functio ...

How about this: "Can you turn a picture into text with just one click?"

Seeking assistance to enhance the 'About Us' page on our website. Each team member has a profile with their email address listed below, but we want to add a picture that disappears when clicked, revealing the email address in its place. You can ...

What is the best method for saving MESH in a global variable following the use of OBJLoader in ThreeJS instead of Object3D?

Currently, I am facing an issue with my code where I use OBJLoader to load an OBJ file and the function returns an Object3D type. However, I need to perform CSG operations on the object which only supports MESH, not Object3D. Is there a method to convert ...

Only compress the initial layer of the array

I put in a lot of effort to create my own flatten function using functional programming. I have everything working smoothly except for some reason, false is not being included in the result. When I try to use it as an answer on codewars, it works for all s ...

What is the best way to remove all elements in jQuery?

I need to remove the selected element in my demo using jstree. I have consulted the plugin's API at http://www.jstree.com/api/#/?f=deselect_all([supress_event]), but it seems that it does not deselect the item properly. Here are the steps I have follo ...

Angular Flot Chart Resizing: A Guide to Dynamic Chart S

I have successfully integrated a Flot chart into my HTML using an Angular directive. Here is how it looks: <flot id="placeholder" dataset="dataset" options="options" height="300px" width="100%" style="width:100%;" ng-disabled="graphLoading" ng-class="{ ...

What is the best way to use the Object3D.lookAt() function to align an ExtrudeGeometry face with an object?

I'm trying to create a 3D Polygon that can face another Object, but I'm struggling to figure out how to do it. I was thinking of using ExtrudeGeometry, but I'm not sure how to apply the Object3D.lookat() function to it. Any suggestions would ...

Issue encountered when trying to add data into MySQL database

Having trouble inserting data into my MySQL database, even though I believe I'm doing it correctly. Does anyone know how to troubleshoot this issue or if I may have overlooked something? Everything seems to be working fine, but for some reason, it&apo ...

Using React JS to iterate over an array and generate a new div for every 3 items

It's a bit challenging for me to articulate my goal effectively. I have a JSON payload that looks like this: { "user": { "id": 4, "username": "3nematix2", "profile_pic": &qu ...

Step-by-step guide to building a personalized entity in ng-admin

I am currently utilizing an admin dashboard powered by ng-admin. According to the documentation, it seems that each entity corresponds to an endpoint in the baseApiUrl. Now, I have a specific question: Here is an example that works: baseApiUrl: entit ...

Dynamic Wordpress content with ajax loading

As someone who is new to php, ajax, and javascript, I've managed to piece together this website using tutorials and somewhat makeshift methods. However, I've encountered a major issue related to URLs that I can't seem to resolve. I' ...

Communication through Collaboration Diagrams

For my software engineering project, I am working on creating communication diagrams. However, I am struggling with understanding how to draw if-then statements. Can anyone provide assistance with this? I have tried looking on YouTube for tutorials, but u ...

AngularJS is not immediately responsive to changes in $window.document.visibilityState

I am currently working with AngularJs version 1.4 and I need to be able to detect when a user is not on the tab of my app and when they return. To achieve this, I attempted using $watch in the following way: $rootScope.$watch(angular.bind($window, functio ...

Steer clear of 405 errors by implementing AJAX in combination with Flask and JINJA templ

Hey there, I'm fairly new to backend work so please bear with me. I've been doing some research but haven't found the answer yet. Currently, I'm working on an application that fetches search results from a 3rd party API. I'm tryi ...

Default values for CSS variables: only apply if the variable has not been previously defined

My Web Component relies on the power of CSS variables. To set default values for these variables is crucial. With their wide usage across multiple files, it's essential to define them once and for all. The initial approach turns the text color to b ...