2012-04-13 51 views
2

我与此代码的工作:的JavaScript/CSS背景定位/拖

<div style="width: 150px; height: 125px; background: #fff; -webkit-border-radius: 10px;-moz-border-radius: 10px;border-radius: 10px; padding: 7px; border: 1px solid #999; cursor: pointer;"> 
    <div style="width: 100%; background: url(IMAGE NAME) no-repeat; cursor: pointer; background-position: center; background-size: 170px; height: 125px;"> 
    </div> 
</div>  

我想让它使用户可以定位自己的照片,以确切的点,而不必再节省图像的副本。我知道你可以制作一个可拖动的元素,让你拖动背景,只是不确定如何。

有人可以帮我吗?

+0

您发布了两个div的代码和一个不明确的问题。在一分钟内如何获得两个upvotes? – j08691 2012-04-13 20:16:07

+0

问题是,我该如何做到这一点,所以我可以将背景位置拖到我想要的位置。我认为这很容易理解。对不起,我的无知。 – Jake 2012-04-13 20:27:46

回答

1
<script> 
    $(function() { 
    $("#draggable_parent").draggable(); 
    }); 
</script> 
<div id="draggable_parent" style="width: 450px; height: 450px; background: #fff; -webkit-border-radius: 10px;-moz-border-radius: 10px;border-radius: 10px; padding: 7px; border: 1px solid #999; cursor: pointer;"> 
    <div id="draggable" style="width: 184px; background: url(IMG_URL) no-repeat; cursor: pointer; background-position: center; border:1px solid; background-size: 170px; height: 125px;"> 
    </div> 
</div> 

我编辑了代码,使用上面的代码,外部div将移动。

+0

不完全;即时通讯寻找一种方式来拖动背景定位。 – Jake 2012-04-13 21:12:01

+0

所以你想要移动父div?我很抱歉,但我只是想了解你想达到的目标。 – 2012-04-13 21:32:31

+0

第一个div的背景位置,我希望能够通过拖动来移动它。 – Jake 2012-04-13 21:34:28