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> </td>
<td> </td>
</tr>
<tr>
<tdstyle="height:500px"> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </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");
});
});