jquery implementation of the product drag selection effect code (from write) _jquery

Source: Internet
Author: User
The effect chart is as follows:


Homepage index.html:
Copy Code code as follows:

<!doctype html>
<meta charset= "Utf-8"/>
<title>drag and Drop</title>
<link rel= "stylesheet" href= "Main.css" >
<script src= "Http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js" ></script>
<script src= "Jquery-ui-1.9.0.custom.min.js" ></script>
<body>
<div class= "Container" >
<section id= "Product" >
<ul class= "Clear" >
<li data-id= "1" >
<a href= "#" >

</a>
</li>
<li data-id= "2" >
<a href= "#" >

</a>
</li>
<li data-id= "3" >
<a href= "#" >

</a>
</li>
<li data-id= "4" >
<a href= "#" >

</a>
</li>
<li data-id= "5" >
<a href= "#" >

</a>
</li>
<li data-id= "6" >
<a href= "#" >

</a>
</li>
<li data-id= "7" >
<a href= "#" >

</a>
</li>
<li data-id= "8" >
<a href= "#" >

</a>
</li>
</ul>
</section>
<aside id= "sidebar" >
<div class= "Basket" >
<div class= "Basket_list" >
<div class= "Head" >
<span class= "name" > Name </span>
<span class= "Count" > Quantity </span>
</div>
<ul>
</ul>
</div>
</div>
</aside>
</div>
<script>
$ (function () {
JQuery UI draggable
$ ("#product li"). Draggable ({

Brings the item back to it place when dragging are over
Revert:true,

Once the dragging starts, we decrease the opactiy of other items
Appending a class as we do so with CSS
Drag:function () {
$ (this). AddClass ("active");
$ (this). Closest ("#product"). AddClass ("active");
},

Removing the CSS classes once dragging is over.
Stop:function () {
$ (this). Removeclass ("active"). Closest ("#product"). Removeclass ("active");
}
});
JQuery Ui droppable
$ (". Basket"). Droppable ({

The class that'll be appended to the to-be-dropped-element (basket)
Activeclass: "Active",

The class that'll be appended once we are hovering the to-be-dropped-element (basket)
Hoverclass: "Hover",

The acceptance of the item once it touches the to-be-dropped-element basket
For different values http://api.jqueryui.com/droppable/#option-tolerance
Tolerance: "Touch",
Drop:function (event, UI) {

var basket = $ (this),
move = Ui.draggable,
ItemId = Basket.find ("ul li[data-id= '" + move.attr ("Data-id") + "'");

To increase the "value by +1 if" same item is already in the basket
if (itemid.html ()!= null) {
Itemid.find ("Input"). Val (parseint (Itemid.find ("input"). Val ()) + 1);
}
else {
Add the dragged item to the basket
Addbasket (basket, move);

Updating the quantity by +1 "rather than adding it to the basket
Move.find ("Input"). Val (parseint (Move.find ("input"). Val ()) + 1);
}
}
});
This function runs ONC EAN item are added to the basket
function Addbasket (basket, move) {
Basket.find ("ul"). Append (' <li data-id= ' + move.attr ("Data-id") + ' > '
+ ' <span class= ' name ' > ' + move.find (' H3 '). HTML () + ' </span> '
+ ' <input class= ' count ' value= ' 1 ' type= ' text ' > '
+ ' <button class= ' delete ' >✕</button> ');
}
The function is triggered once delete button is pressed
$ (". Basket ul Li Button.delete"). Live ("Click", Function () {
$ (this). Closest ("Li"). Remove ();
});
});
</script>
</body>

Jquery-ui-1.9.0.custom.min.js
MAIN.CSS:
Copy Code code as follows:

/* 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;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.