">
HomeWeb Front-endJS Tutorialjquery implements product drag selection effect code (self-written)_jquery

The rendering is as follows:
jquery implements product drag selection effect code (self-written)_jquery
jquery implements product drag selection effect code (self-written)_jquery
Main page index.html:
Copy code The code is as follows:





Drag and drop






<script> <BR>$(function () { <BR>// jQuery UI Draggable <BR>$("#product li").draggable({ <br><br>// brings the item back to its place when dragging is over <BR>revert:true, <br><br>// once the dragging starts, we decrease the opactiy of other items <BR>// Appending a class as we do that with CSS <BR>drag:function () { <BR>$(this).addClass("active"); <BR>$(this).closest("#product").addClass("active"); <BR>}, <br><br>// removing the CSS classes once dragging is over. <BR>stop:function () { <BR>$(this).removeClass("active").closest("#product").removeClass("active"); <BR>} <BR>}); <BR>// jQuery Ui Droppable <BR>$(".basket").droppable({ <br><br>// The class that will be appended to the to-be-dropped-element (basket) <BR>activeClass:"active", <br><br>// The class that will be appended once we are hovering the to-be-dropped-element (basket) <BR>hoverClass:"hover", <br><br>// The acceptance of the item once it touches the to-be-dropped-element basket <BR>// For different values http://api.jqueryui.com/droppable/#option-tolerance <BR>tolerance:"touch", <BR>drop:function (event, ui) { <br><br>var basket = $(this), <BR>move = ui.draggable, <BR>itemId = basket.find("ul li[data-id='" move.attr("data-id") "']"); <br><br>// To increase the value by 1 if the same item is already in the basket <BR>if (itemId.html() != null) { <BR>itemId.find("input").val(parseInt(itemId.find("input").val()) 1); <BR>} <BR>else { <BR>// Add the dragged item to the basket <BR>addBasket(basket, move); <br><br>// Updating the quantity by 1" rather than adding it to the basket <BR>move.find("input").val(parseInt(move.find("input").val()) 1); <BR>} <BR>} <BR>}); <BR>// This function runs onc ean item is added to the basket <BR>function addBasket(basket, move) { <BR>basket.find("ul").append('<li data-id="' move.attr("data-id") '">' <BR> '<span class="name">' move.find("h3").html() '' <BR> '<input class="count" value="1" type="text">' <BR> '<button class="delete">✕'); <BR>} <BR>// The function that is triggered once delete button is pressed <BR>$(".basket ul li button.delete").live("click", function () { <BR>$(this).closest("li").remove(); <BR>}); <BR>}); <BR></script>


 
jquery-ui-1.9.0.custom.min.js
main.css:
复制代码 代码如下:

/* reset & .clear
----------------------------*/
* {
margin: 0;
padding: 0;
}
.clear:before,
.clear:after {
content: " ";
display: table;
}
.clear:after { clear: both }
.clear { *zoom: 1 }
/* MAIN
----------------------------*/
body {
font: normal 12px/1.3 arial, sans-serif;
background-color: #eee;
}
li { list-style: none }
a { text-decoration: none }
.container {
position: relative;
width: 920px;
margin: 30px auto;
}
.container #product {
position: relative;
z-index: 2;
float: left;
width: 670px;
}
.container #sidebar {
position: relative;
z-index: 1;
float: right;
width: 224px;
}
/* PRODUCTS
----------------------------*/
#product ul {
width: 680px;
margin-left: -10px; }
#product ul li {
position: relative;
float: left;
width: 150px;
margin: 0 0 10px 10px;
padding: 5px;
background-color: #fff;
border-radius: 4px;
-webkit-box-shadow: 0 1px 2px rgba(0, 0, 0, .2);
box-shadow: 0 1px 2px rgba(0, 0, 0, .2);
-webkit-transition: -webkit-transform .1s ease;
-moz-transition: -webkit-transform .1s ease;
-o-transition: -webkit-transform .1s ease;
-ms-transition: -webkit-transform .1s ease;
transition: transform .1s ease;
}
#product ul li:hover {
background-color: #fff8c1;
}
#product.active ul li {
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=40)";
filter: alpha(opacity = 40);
opacity: .4;
}
#product.active ul li.active {
z-index: 2;
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)";
filter: alpha(opacity = 100);
opacity: 1;
-webkit-transform-origin: 50% 50%;
-moz-transform-origin: 50% 50%;
-o-transform-origin: 50% 50%;
-ms-transform-origin: 50% 50%;
transform-origin: 50% 50%;
-webkit-transform: scale(.6);
-moz-transform: scale(.6);
-o-transform: scale(.6);
-ms-transform: scale(.6);
transform: scale(.6);
}
#product ul li a {
display: block;
color: #000
}
#product ul li a h3 {
margin-top: 5px;
}
#product ul li a h3,
#product ul li a p {
white-space: nowrap;
overflow: hidden;
-o-text-overflow: ellipsis;
-ms-text-overflow: ellipsis;
text-overflow: ellipsis;
}
#product ul li a img { width:150px;height:150px;display: block }
/* BASKET
----------------------------*/
.basket {
position: relative;
}
.basket .basket_list {
width: 220px;
background-color: #fff;
border: 2px dashed transparent;
border-radius: 4px;
-webkit-box-shadow: 0 1px 2px rgba(0, 0, 0, .2);
box-shadow: 0 1px 2px rgba(0, 0, 0, .2);
}
.basket.active .basket_list,
.basket.hover .basket_list { border-color: #ffa0a3 }
.basket.active .basket_list { background-color: #fff8c1 }
.basket.hover .basket_list { background-color: #ffa0a3 }
/* .head */
.basket .head {
overflow: hidden;
margin: 0 10px;
height: 26px;
line-height: 26px;
color: #666;
border-bottom: 1px solid #ddd;
}
.basket .head .name { float: left }
.basket .head .count { float: right }
/* .head */
.basket ul { padding-bottom: 10px }
.basket ul li {
position: relative;
clear: both;
overflow: hidden;
margin: 0 10px;
height: 26px;
line-height: 32px;
border-bottom: 1px dashed #eee;
}
.basket ul li:hover { border-bottom-color: #ccc }
.basket ul li span.name {
display: block;
float: left;
width: 165px;
font-weight: bold;
white-space: nowrap;
overflow: hidden;
-o-text-overflow: ellipsis;
-ms-text-overflow: ellipsis;
text-overflow: ellipsis;
-webkit-transition: width .2s ease;
-moz-transition: width .2s ease;
-o-transition: width .2s ease;
-ms-transition: width .2s ease;
transition: width .2s ease;
}
.basket ul li:hover span.name { width: 146px }
.basket ul li input.count {
float: right;
margin: 3px 2px 0 0;
width: 25px;
line-height: 20px;
text-align: center;
border: 0;
border-radius: 3px;
background-color: #ddd;
}
.basket ul li button.delete {
position: absolute;
right: 30px;
top: 3px;
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";
filter: alpha(opacity = 0);
opacity: 0;
width: 20px;
line-height: 20px;
height: 20px;
text-align: center;
font-size: 11px;
border: 0;
color: #EE5757;
background-color: #eee;
border-radius: 3px;
cursor: pointer;
-webkit-transition: opacity .2s ease;
-moz-transition: opacity .2s ease;
-o-transition: opacity .2s ease;
-ms-transition: opacity .2s ease;
transition: opacity .2s ease;
}
.basket ul li:hover button.delete {
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)";
filter: alpha(opacity = 100);
opacity: 1;
}
.basket ul li button.delete:hover {
color: #fff;
background-color: #ffa0a3;
}
.basket ul li button.delete:active {
color: #fff;
background-color: #EE5757;
}
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
iBatis和MyBatis:哪个更适合你?iBatis和MyBatis:哪个更适合你?Feb 19, 2024 pm 04:38 PM

iBatis与MyBatis:你应该选择哪个?简介:随着Java语言的快速发展,许多持久化框架也应运而生。iBatis和MyBatis是两个备受欢迎的持久化框架,它们都提供了一种简单而高效的数据访问解决方案。本文将介绍iBatis和MyBatis的特点和优势,并给出一些具体的代码示例,帮助你选择合适的框架。iBatis简介:iBatis是一个开源的持久化框架

CS玩家的首选:推荐的电脑配置CS玩家的首选:推荐的电脑配置Jan 02, 2024 pm 04:26 PM

1.处理器在选择电脑配置时,处理器是至关重要的组件之一。对于玩CS这样的游戏来说,处理器的性能直接影响游戏的流畅度和反应速度。推荐选择IntelCorei5或i7系列的处理器,因为它们具有强大的多核处理能力和高频率,可以轻松应对CS的高要求。2.显卡显卡是游戏性能的重要因素之一。对于射击游戏如CS而言,显卡的性能直接影响游戏画面的清晰度和流畅度。建议选择NVIDIAGeForceGTX系列或AMDRadeonRX系列的显卡,它们具备出色的图形处理能力和高帧率输出,能够提供更好的游戏体验3.内存电

kafka可视化工具对比分析:如何选择最合适的工具?kafka可视化工具对比分析:如何选择最合适的工具?Jan 05, 2024 pm 12:15 PM

如何选择合适的Kafka可视化工具?五款工具对比分析引言:Kafka是一种高性能、高吞吐量的分布式消息队列系统,被广泛应用于大数据领域。随着Kafka的流行,越来越多的企业和开发者需要一个可视化工具来方便地监控和管理Kafka集群。本文将介绍五款常用的Kafka可视化工具,并对比它们的特点和功能,帮助读者选择适合自己需求的工具。一、KafkaManager

揭秘Pip镜像源:如何选择最适合个人需求的镜像源?揭秘Pip镜像源:如何选择最适合个人需求的镜像源?Jan 16, 2024 am 09:26 AM

Pip镜像源大揭秘:如何选择最适合你的镜像源?简介:Pip是Python中最常用的软件包管理工具之一,能够方便地安装、升级和移除Python包。在使用Pip的过程中,选择适合自己的镜像源可以显著提高安装速度和稳定性。本文将为大家介绍常见的几种镜像源,并提供具体的代码示例,以便读者可以轻松选择最适合自己的镜像源。一、什么是镜像源?在使用Pip

在大数据场景下的MySQL储存引擎选择:MyISAM、InnoDB、Aria对比分析在大数据场景下的MySQL储存引擎选择:MyISAM、InnoDB、Aria对比分析Jul 24, 2023 pm 07:18 PM

在大数据场景下的MySQL储存引擎选择:MyISAM、InnoDB、Aria对比分析随着大数据时代的到来,传统的储存引擎在面对高并发、大数据量的情况下往往无法满足业务需求。MySQL作为最流行的关系型数据库管理系统之一,其储存引擎的选择显得尤为重要。在本文中,我们将对大数据场景下MySQL常用的储存引擎MyISAM、InnoDB、Aria进行对比分析,并给出

JavaScript 如何实现图片的左右拖动切换效果?JavaScript 如何实现图片的左右拖动切换效果?Oct 21, 2023 am 09:27 AM

JavaScript如何实现图片的左右拖动切换效果?在现代网页设计中,动态效果可以增加用户体验和视觉吸引力。而图片的左右拖动切换效果是一种常见的动态效果,它可以让用户通过拖动图片来切换不同的内容。在本文中,我们将介绍如何使用JavaScript来实现这种图片切换效果,并提供具体的代码示例。首先,我们需要准备一些HTML和CSS代码,用于创建一个包含多个图片

JavaScript 如何实现弹出框的拖动的同时限制在页面可见区域内?JavaScript 如何实现弹出框的拖动的同时限制在页面可见区域内?Oct 18, 2023 pm 12:26 PM

JavaScript如何实现弹出框的拖动的同时限制在页面可见区域内?在网页开发中,我们常常会遇到需要实现弹出框或对话框的需求。而其中一个常见的需求就是让这些弹出框能够随意拖动,并且限制在页面的可见区域内。本文将介绍如何使用JavaScript来实现这个功能,并提供相应的代码示例。首先,我们需要了解一些基本概念。在Web开发中,页面的可见区域可以用窗口的宽度

为什么学习Python是一个明智的职业选择?为什么学习Python是一个明智的职业选择?Sep 08, 2023 pm 01:45 PM

为什么学习Python是一个明智的职业选择?Python,作为一门易学易用且功能强大的编程语言,正日益成为职场人士的首选。无论你是初学者还是有一定编程经验的专业人士,学习Python都是一个明智的职业选择。本文将探讨学习Python的优势,并提供一些Python代码示例来帮助读者更好地理解。Python的易学性相比其他编程语言,Python具备非常低的学习曲

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),