當前位置:首頁 » 網購平台 » 手機端jquery拖動加入購物車動畫效果
擴展閱讀
寧波奧德賽優惠價格 2021-03-15 14:26:02
丹尼斯購物卡能掛失么 2021-03-15 14:25:58
淘寶購物指紋驗證失敗 2021-03-15 14:24:44

手機端jquery拖動加入購物車動畫效果

發布時間: 2021-02-07 18:28:50

1. 如何在手機瀏覽器實現jquery ui 中的draggable拖動事件

這個是無法實現的 。它違反了瀏覽器的安全原則。
在你當前頁面中是無內法監聽到 iframe中的 事件的容,更不用說去拖動title 反過來操作父容器裡面的東西了。這個好好想一下,如果當你用iframe嵌套了任意一個網頁,這個網頁卻能操控你父容器的內容(你想拖動iframe裡面的tile來重新設置iframe在父容器裡面的位置,就相當於在操縱父容器了),將會發生什麼? 因此是這個做不到的。不要浪費了力氣了。

只能像1L說的,把iframe 包裹在一個div裡面。拖到iframe外層的div的一部分(劃出類似title的一部分)來進行實現。

2. jquery 實現加入購物車功能

參考以下代碼:

注意需要導入.js.

<!DOCTYPEhtml>
<html>
<head>
<title>購物車----jQuery</title>
<metacharset="utf-8"/>
<styletype="text/css">
h1{
text-align:center;
}
table{
margin:0auto;
width:60%;
border:2pxsolid#aaa;
border-collapse:collapse;
}
tableth,tabletd{
border:2pxsolid#aaa;
padding:5px;
}
th{
background-color:#eee;
}
</style>
<scripttype="text/javascript"src="./js/jquery.js"></script>
<scripttype="text/javascript">
functionadd_shoppingcart(btn){//將btn(dom)轉換為jQuery對象
//先獲取商品名字和單價還有庫存以備後面使用
var$tds=$(btn).parent().siblings();
//$tds.eq(0)是jQuery對象$tds[0]是DOM對象
varname=$tds.eq(0).html();//string
varprice=$tds.eq(1).html();//string
varstock=$tds.eq(3).html();//string

//查看庫存是否還有<=0
if(stock<=0){
return;
}

//無論購物車中是否有該商品,庫存都要-1
$tds.eq(3).html(--stock);

//在添加之前確定該商品在購物車中是否存在,若存在,則數量+1,若不存在則創建行
var$trs=$("#goods>tr");
for(vari=0;i<$trs.length;i++){
var$gtds=$trs.eq(i).children();
vargName=$gtds.eq(0).html();
if(name==gName){//若存在
varnum=parseInt($gtds.eq(2).children().eq(1).val());
$gtds.eq(2).children().eq(1).val(++num);//數量+1
//金額從新計算
$gtds.eq(3).html(price*num);
return;//後面代碼不再執行
}
}
//若不存在,創建後追加
varli=
"<tr>"+
"<td>"+name+"</td>"+
"<td>"+price+"</td>"+
"<tdalign='center'>"+
"<inputtype='button'value='-'onclick='decrease(this);'/>"+
"<inputtype='text'size='3'readonlyvalue='1'/>"+
"<inputtype='button'value='+'onclick='increase(this);'/>"+
"</td>"+
"<td>"+price+"</td>"+
"<tdalign='center'>"+
"<inputtype='button'value='x'onclick='del(this);'/>"+
"</td>"+
"</tr>";
//追加到#goods後面
$("#goods").append($(li));

//總計功能
total();
}

//輔助方法--單擊購物車中的"+""-""x"按鈕是找到相關商品所在td,以jQuery對象返回
functionfindStock(btn){
varname=$(btn).parent().siblings().eq(0).html();//獲取商品名字
//注意table默認有行分組,若此處使用$("#table1>tr:gt(0)")則找不到任何tr
var$trs=$("#table1>tbody>tr:gt(0)");
for(vari=0;i<$trs.length;i++){
varfName=$trs.eq(i).children().eq(0).html();
if(name==fName){//找到匹配的商品
return$trs.eq(i).children().eq(3);
}
}
}

//增加"+"功能
functionincrease(btn){
//獲取該商品庫存看是否<=0
var$stock=findStock(btn);
varstock=$stock.html();
if(stock<=0){
return;
}
//庫存-1
$stock.html(--stock);
//購物車數據改變
var$td=$(btn).prev();
varnum=parseInt($td.val());//number
//num此時為number類型(在計算時會自動轉換為number類型)
$td.val(++num);
//獲取單價,再加計算前要先轉換為number類型
varprice=parseInt($(btn).parent().prev().html());
$(btn).parent().next().html(num*price);

//總計功能
total();
}

//減少"-"功能
functiondecrease(btn){
//該商品數量=1時候不能再減少
varnum=parseInt($(btn).next().val());
if(num<=1){
return;
}
var$stock=findStock(btn);
//庫存+1
varstock=$stock.html();
$stock.html(++stock);
//商品數量-1
$(btn).next().val(--num);
//從新計算金額
varprice=parseInt($(btn).parent().prev().html());
$(btn).parent().next().html(price*num);

//總計功能
total();
}

//"x"刪除按鈕功能
functiondel(btn){
//將商品數量歸還庫存
var$stock=findStock(btn);
varstock=parseInt($stock.html());
varnum=parseInt($(btn).parent().prev().prev().children().eq(1).val());
$stock.html(num+stock);
//清空改行商品列表
$(btn).parent().parent().remove();

//總計功能
total();
}
//總計功能
functiontotal(){
//獲取所有購物車中的trs
var$trs=$("#goodstr");
varamount=0;
for(vari=0;i<$trs.length;i++){
varmoney=parseInt($trs.eq(i).children().eq(3).html());
amount+=money;
}
//寫入總計欄
$("#total").html(amount);
}
</script>
</head>
<body>
<h1>真劃算</h1>
<tableid="table1">
<tr>
<th>商品</th>
<th>單價(元)</th>
<th>顏色</th>
<th>庫存</th>
<th>好評率</th>
<th>操作</th>
</tr>
<tr>
<td>羅技M185滑鼠</td>
<td>80</td>
<td>黑色</td>
<td>5</td>
<td>98%</td>
<tdalign="center">
<inputtype="button"value="加入購物車"onclick="add_shoppingcart(this);"/>
</td>
</tr>
<tr>
<td>微軟X470鍵盤</td>
<td>150</td>
<td>黑色</td>
<td>9028</td>
<td>96%</td>
<tdalign="center">
<inputtype="button"value="加入購物車"onclick="add_shoppingcart(this);"/>
</td>
</tr>
<tr>
<td>洛克iphone6手機殼</td>
<td>60</td>
<td>透明</td>
<td>672</td>
<td>99%</td>
<tdalign="center">
<inputtype="button"value="加入購物車"onclick="add_shoppingcart(this);"/>
</td>
</tr>
<tr>
<td>藍牙耳機</td>
<td>100</td>
<td>藍色</td>
<td>8937</td>
<td>95%</td>
<tdalign="center">
<inputtype="button"value="加入購物車"onclick="add_shoppingcart(this);"/>
</td>
</tr>
<tr>
<td>金士頓U盤</td>
<td>70</td>
<td>紅色</td>
<td>482</td>
<td>100%</td>
<tdalign="center">
<inputtype="button"value="加入購物車"onclick="add_shoppingcart(this);"/>
</td>
</tr>
</table>

<h1>購物車</h1>
<table>
<thead>
<tr>
<th>商品</th>
<th>單價(元)</th>
<th>數量</th>
<th>金額(元)</th>
<th>刪除</th>
</tr>
</thead>
<tbodyid="goods">
</tbody>
<tfoot>
<tr>
<tdcolspan="3"align="right">總計</td>
<tdid="total"></td>
<td></td>
</tr>
</tfoot>
</table>
</body>
</html>

最終效果圖:

3. jquery曲線飛入購物車效果遇到一點小問題

提供一個思路,僅供參考:

假設你用的是animate,再假設你是通過改變"運動塊"的left值和top值來實現專運動的。
那麼,既然屬是曲線,就會有公式。假如一個拋物線的公式:x2=-2py(x>0)
那麼,你就可以寫一個循環,定義一個變數來表達left和top值,直到到達指定位置,循環結束。示例代碼:

while($top<900){
$left=-sqrt(-2p*$top);
$('.div').animate({left:$left,top:$top},100);
}

這是根據上面假設的拋物線公式確定的。不知道你是否能看懂。

4. 用jquery easyui 做了一個拖拽效果,還用jquery的動畫效果做了一個div運動效果,怎麼讓兩者結合

不如不用ui試試,我的想法是先執行mousedown,然後使滑鼠到達的top和left全都存在變數中,之內後mouseup然後再用容animate執行下div中css變化top和left為變數值,這樣就先拖拽再運動了,但是我沒試驗過,只是個思路

5. 如何用javascript實現天貓收藏商品進購物車的動畫效果

需要使用拋物線函數來對想要移動的元素進行編輯,你可以網路搜索JS拋物線函數,結果中前兩個,都有詳細的解釋和代碼。

6. jquery實現添加到購物車拖放功能 像百度旅遊定製旅遊一樣 如下圖

這功能網路內部有專門開發的。
拖拉帶拽的功能你可以看下jquery ui,裡面有部分功能可以拖動和獲取的,這功能要實現,代碼會有點復雜。
你先自己搜搜看吧

7. 求jQuery或js實現淘寶上面的圖標菜單在手機上滑動的效果。m.taobao.com

在PC端的網頁上,用CSS加個滾動條就可以滑動了,樣式為overflow-x:auto;,
但是在手機端這個樣試是不起作用的,在目前三個主流手機端 ios 、android、wp的系統上,只有wp的系統支持這個樣式,ios和android都不支持,要想在手機端實現同樣的功能,那麼你可以用手機端屬的JS事件來控制
xxx.addEventListener("touchstart",function(e){
//這里放手指移上去的代碼,可以取到手指移上去的屏幕坐標,在e中取。
},false);

document.addEventListener("touchend",function(e){
//這里放手指移出去的代碼,可以取到手指移出後屏幕上的坐標,在e中取。
},false);

document.addEventListener("touchmove",function(e){
//這里放手機在屏幕上劃動的代碼,可以隨時取得手指的坐標,並對元素做相應的調整。
},false);

以上的手機觸屏事件分別對應著PC網頁端的
onmousedown事件、onmouseup事件和onmousemove事年,
注意以上的手機端的JS事件在網頁端是無效的(touchstart,touchend,touchmove)

8. 如何讓jquery動畫效果在屏幕滾動到指定位置才執行

1、新建一個html文件,命名為test.html。

9. JavaScript: jquery框架的滑出滑入的動畫效果是怎麼實現的

clientHeight

然後遞歸,直到這個高度為0,或者直到這個高度為一個指定的高度

function showBox()
{
if (sb != null){
clearTimeout(sb);
}
if (cb != null) {
clearTimeout(cb);
}
var o = $('rbbox');
o.style.display = 'block';
var H = parseInt(o.style.height)
o.style.height = (o.clientHeight + Math.ceil((55 - o.clientHeight) * 0.035)) + "px";
if (o.clientHeight < 55) {
sb = setTimeout(function(){showBox()}, 2);
}
else {
cb = setTimeout(function(){closeBox()}, 3800);
return;
}
}

function closeBox(msg)
{
if (cb != null) {
clearTimeout(cb);
}
var o = $('rbbox');
var dy = Math.ceil((parseInt(o.style.height) - 4) * 0.875).toString();
o.style.height = dy + "px";
if(o.clientHeight <= 5){
document.getElementById("rbbox").style.display = 'none';
return;
}
cb = setTimeout(function(){closeBox()}, 3);
}

div#rbbox {
position: fixed;
right: 2px;
bottom: 2px;
height: 0px;
width: auto;
overflow: hidden;
border:1px #ff0000 solid;
background-color: #FFCC00;
text-align:justify;
}

10. 求助:怎麼樣用jQuery製作出一個圖片飛入購物車的動畫

給你個示例吧,應該能幫助到你

這是html

<inputid="Button1"type="button"value="button"/>
<tablestyle="width:100%;">
<tr>
<td>
<divstyle="width:100px;height:100px;border:1pxsolid#f08080"id="shop">購物車</div>
</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<tdstyle="height:500px">&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>
<divstyle="width:50px;height:50px;background-color:#f08080"id="proct">
商品
</div>
</td>
</tr>
</table>

這個是jQuery代碼:

$(function(){
$("#Button1").click(function(){
varshopOffset=$("#shop").offset();
varcloneDiv=$("#proct").clone();
varproOffset=$("#proct").offset();
cloneDiv.css({"position":"absolute","top":proOffset.top,"left":proOffset.left});
$("#proct").parent().append(cloneDiv);

cloneDiv.animate({
left:shopOffset.left,
top:shopOffset.top
},"slow");
});
});