防百度的个性化页面JS

花了好长时间整的JS,个性化页面拖曳功能
$(document).ready(function() {
if (typeof(console) == 'undefined') {
console = {
debug : function() {
}
}
}
var cmd = console;
var sDrag = $('#sampleDivForDrag');
var fDrag = $('#fordrag'); // proxy

$("div", $("#lay_tab")).each(function() {
if ($(this).attr("id")) {
$(this).click(function() {
$("div", $("#lay_tab")).each(function() {
$(this).removeClass('on')
});
var id = $(this).attr("id");
if (id == 'lay2') {
$('#layout >tbody >tr >td').each(function(i) {
$(this).attr('id', 'modtd2_' + i);
$(this).attr('class', 'c2t' + (i + 1) + ' lay2td' + i);
});

} else if (id == 'lay5') {
$('#layout >tbody >tr >td').each(function(i) {
$(this).attr('id', 'modtd4_' + i);
$(this).attr('class', 'c3t' + (i + 1) + ' lay5td' + i);
});
} else if (id == 'lay4') {
$('#layout >tbody >tr >td').each(function(i) {
$(this).attr('id', 'modtd4_' + i);
$(this).attr('class', 'c3t' + (i + 1) + ' lay4td' + i);
});
} else if (id == 'lay3') {
$('#layout >tbody >tr >td').each(function(i) {
$(this).attr('id', 'modtd_' + i);
$(this).attr('class', 'c2t' + (i + 1) + ' lay3td' + i);
});

// $('#modtd_0').addClass('c2t1 lay2td0')
} else if (id == 'lay1') {
$('#layout >tbody >tr >td').each(function(i) {
$(this).attr('id', 'modtd_' + i);
$(this).attr('class', 'c2t' + (i + 1) + ' lay1td' + i);
});

// $('#modtd_0').addClass('c2t1 lay2td0')
} else if (id == 'lay0') {
$('#layout >tbody >tr >td').each(function(i) {
$(this).attr('id', 'modtd_' + i);
$(this).attr('class', 'c1t' + (i + 1) + ' lay0td' + i);
});

// $('#modtd_0').addClass('c2t1 lay2td0')
}

$(this).addClass("on");
});
}
});

// return;

var model = $("div[rel]='drag'");
var rels = {};
var tds = {};
cmd.debug(model);
$.each(model, function() {
var tar = $(this);

$(this).find('table:first').each(function() {


$(this).drag("init", function() {
$('#layout >tbody >tr >td:visible').each(function(i) {
var id = $(this).attr('class');
p = $(this).offset();
tds[id] = jQuery.extend(p, {
w : $(this).width(),
h : $(this).height()
});
$(this).css('background-color',i+'f666'+i);

});

$("div[rel]='drag':visible").each(function() {

var id = $(this).attr('id');
p = $(this).offset();
rels[id] = jQuery.extend(p, {
w : $(this).width(),
h : $(this).height()
});
//$(this).append($(this).offset());
});
var p = $(this).offset();
fDrag.css('left', p.left);
fDrag.css('top', p.top);
fDrag.show();
cmd.debug('init');

}).drag("start", function() {
cmd.debug('start');
// fDrag.append($(this).parent());
var w =$(this).parent().width();
fDrag.append($(this).parent().clone());
$(this).parent().hide();
$(this).parent().before(sDrag);
sDrag.show();
fDrag.css('width',w);
return fDrag;

}).drag(function(e, dd) {
$(dd.proxy).css({
top : dd.offsetY,
left : dd.offsetX,
cursor : 'move'
});

var x = e.pageX, y = e.pageY;

// check div
for (dd in rels) {
var d = rels[dd];

if ((d.left < x && x < (d.left + d.w))
&& (d.top < y && y < (d.top + d.h))) {
// cmd.debug(d);
sDrag.remove();
if (y < (d.top+ d.h / 2))
$('#' + dd + '').before(sDrag);

else
$('#' + dd + '').after(sDrag);
return true;
}
}

// check td
for (td in tds) {
var t = tds[td];
if ((t.left < x && x < (t.left + t.w))
&& (t.top < y && y < (t.top + t.h))) {
// cmd.debug(td);
sDrag.remove();

$('td[class=\"' + td + '\"]').append(sDrag);



return true;
}
}
return true;

}).drag("end", function(ev, dd) {

sDrag.hide();
$(document.body).append(sDrag.clone());
var r = $(this).parent().offset();
$(this).css('left', r.left);
$(this).css('top', r.top);
sDrag.replaceWith($(this).parent().show());
fDrag.empty();
fDrag.css({
left : 0,
top : 0
});

});

$(this).css('cursor', 'move');
});

});


cmd.debug(rels);
cmd.debug(tds);

});
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值