hjl416148489 2015-05-27 09:23:59 4068次浏览 0条回复 8 7 0

许愿墙

1.首先我们遍历出所有的许愿列表:

$query = mysql_query("select * from wishing_wall order by id desc limit 0, 50"); 
while ($row = mysql_fetch_array($query)) { 
    list($left, $top, $zindex) = explode('|', $row['xyz']); 
    $time = strtotime($row['addtime']); 
 
    $notes .= "<dl class='paper a" . $row['color'] . "'  style='left:" . $left . "px;top:" . $top . "px;z-index:" . $zindex . "' data-id=" . $row['id'] . "> 
<dt><span class='username'>" . $row['name'] . "</span><span class='num'>" . $row['id'] . "</span></dt> 
<dd class='content'>" . $row['content'] . "</dd> 
<dd class='bottom'><span class='time'>" . tranTime($time) . "</span><a class='close' href='javascript:void(0);'></a></dd> 
</dl>";

接着我们把许愿列表放到.container里面:

<div class="container"style="position: relative"> 
  <?php echo $notes; ?> 
</div>

通过jQueryUI拖动许愿墙悬浮层代码如下:

var zIndex = 0; 
function make_draggable(elements) { 
    elements.draggable({ 
        handle: 'dt', //拖动把手 
        opacity: 0.8, 
        containment: 'parent', //拖动范围  
        start: function(e, ui) { 
            ui.helper.css('z-index', ++zIndex) 
        }, 
        stop: function(e, ui) { 
            $.get('ajax.php?act=update_position', { 
                x: ui.position.left, 
                y: ui.position.top, 
                z: zIndex, 
                id: parseInt(ui.helper.attr("data-id")) 
            }); 
        } 
    }); 
}

PHP保存位置:

$act = htmlspecialchars($_GET['act']); 
if ($act == 'update_position') { 
    if (!is_numeric($_GET['id']) || !is_numeric($_GET['x']) || !is_numeric($_GET['y']) || !is_numeric($_GET['z'])) 
        die("0"); 
 
    $id = intval($_GET['id']); 
    $x = intval($_GET['x']); 
    $y = intval($_GET['y']); 
    $z = intval($_GET['z']); 
 
    mysql_query("UPDATE wishing_wall SET xyz='" . $x . "|" . $y . "|" . $z . "' WHERE id=" . $id); 
 
    echo "1"; 
}

许愿墙下载:http://www.sucaihuo.com/php/136.html

觉得很赞
    没有找到数据。
您需要登录后才可以回复。登录 | 立即注册