具有保存位置的JQuery可拖动图像

Iva*_*ich 8 css jquery jquery-ui image draggable

好吧,它变得尴尬,已经搜索并尝试了大约5个小时,我只是在圈子里跑...

场景很简单:它是用户配置文件的标题图像,可以将其拖动到某个位置,然后将图像的顶部位置保存到数据库中.

感谢Beetroot-Beetroot的"遏制:'父母'"我对这段代码感兴趣,实际上我想要它做出反应!除了一个大问题.图片只是跳到顶部或底部.没有平滑的滚动?如果我将"父母"改为"父母",它会很好地滚动但是...当然遏制不再存在了.救命?:d

JS

$(function(){
    $(".headerimage").css('cursor','s-resize');
    $(".headerimage").draggable({ containment: 'parent', scroll: false, axis: "y",    stop: function(event, ui) {
            var data = "profileheaderposition="+ui.position.top;
            var destination = "/modules/users/profile/save.php";
            get_data(data, destination, function(test){
                notice(test);
            });
        }
    });                 
});
Run Code Online (Sandbox Code Playgroud)

所以最后但并非最不重要的是,Header包括在内:

<div class="<?php if ($user->id == $profileuser->id) echo "changer"; ?> ui-corner-all" id="profileheader" style="overflow: hidden; width: 650px; height: 260px; position:relative;">
<?php if($profile->profileheader){
    $size = getimagesize($profile->profileheader);
?>
<img id="" class="draggable headerimage" style="position: absolute; top: <?php echo $profile->profileheaderposition; ?>px;" src="<?php echo $profile->profileheader; ?>" alt="profileheader" width="650" />
Run Code Online (Sandbox Code Playgroud)

正如我所说,几个小时的谷歌搜索没有给出任何结果 - 如果我不保存结果它会工作得很好,但哦,好吧......

- 编辑 -

现在我正要哭出来 - 我已经在这个上设置了奖金和帮助我的工具,但在我的网页上有一个来宾帐户:http://www.animize.de

在那里,您可以使用用户名:Gast和pw gast登录页面 - 单击名称(gast)右上角的,您将看到配置文件 - 您可以在那里移动标题图片 - 当然它应该表现得很好用另一种方式 - 帮助:(

QQp*_*ing 10

试试这个小提琴.

我在drag事件中添加了一个if语句,用于检查图像的当前位置,并ui.position.top在条件返回true时将当前顶部位置设置为,这样可拖动事件在击中div的边界时不会增加或减少顶部位置.这样你就可以保持div的位置属性.