:) I can't get the position ot objects relative to it's container. I get only the position on whole page.Here is my code:
<style>
.draggable { width: 150px; height: 0px; cursor:move; bottom: border:solid; border-color:#000; }
<?PHP if($userinfo->use_colors != '0'): ?>
#container { width: 450px; height:80px; background-color:<?=$userinfo->background?>; }
<?PHP else: ?>
#container { width: 450px; height:80px; background:url(/backgrounds/<?=$userinfo->image?>); }
<?PHP endif; ?>
</style>
<script>
$(function() {
$( "#draggable" ).draggable({ cursor: "move",containment: "#container", scroll: false,
drag: function() {
var position = $(this).position();
var xPos = $(this).position().left;
var yPos = $(this).position().top;
$(this).text('x: ' + xPos + 'y: ' + yPos);
}
});
$( "#draggable2" ).draggable({ cursor: "move",containment: "#container", scroll: false });
$( "#draggable3" ).draggable({ cursor: "move",containment: "#container", scroll: false });
$( "#draggable4" ).draggable({ cursor: "move",containment: "#container", scroll: false });
});
</script>
<div id="container">
<div id="draggable" class="draggable" style="position:relative;top:0px;left:80px;">
.::[ NowPlaying SIGnature ]::.
</div>
<div id="draggable2" class="draggable" style="position:relative;top:20px;left:80px;">
Artist - title
</div>
<div id="draggable3" class="draggable" style="position:relative;top:40px;left:80px;">
Album: (Year)
</div>
<div id="draggable4" class="draggable" style="position:relative;top:60px;left:80px;">
Genre:
</div>
</div>
:) I can't get the position ot objects relative to it's container. I get only the position on whole page.Here is my code:
<style>
.draggable { width: 150px; height: 0px; cursor:move; bottom: border:solid; border-color:#000; }
<?PHP if($userinfo->use_colors != '0'): ?>
#container { width: 450px; height:80px; background-color:<?=$userinfo->background?>; }
<?PHP else: ?>
#container { width: 450px; height:80px; background:url(/backgrounds/<?=$userinfo->image?>); }
<?PHP endif; ?>
</style>
<script>
$(function() {
$( "#draggable" ).draggable({ cursor: "move",containment: "#container", scroll: false,
drag: function() {
var position = $(this).position();
var xPos = $(this).position().left;
var yPos = $(this).position().top;
$(this).text('x: ' + xPos + 'y: ' + yPos);
}
});
$( "#draggable2" ).draggable({ cursor: "move",containment: "#container", scroll: false });
$( "#draggable3" ).draggable({ cursor: "move",containment: "#container", scroll: false });
$( "#draggable4" ).draggable({ cursor: "move",containment: "#container", scroll: false });
});
</script>
<div id="container">
<div id="draggable" class="draggable" style="position:relative;top:0px;left:80px;">
.::[ NowPlaying SIGnature ]::.
</div>
<div id="draggable2" class="draggable" style="position:relative;top:20px;left:80px;">
Artist - title
</div>
<div id="draggable3" class="draggable" style="position:relative;top:40px;left:80px;">
Album: (Year)
</div>
<div id="draggable4" class="draggable" style="position:relative;top:60px;left:80px;">
Genre:
</div>
</div>
Share
Improve this question
edited Feb 14, 2011 at 14:28
CappY
asked Feb 14, 2011 at 14:21
CappYCappY
1,5801 gold badge17 silver badges32 bronze badges
1 Answer
Reset to default 5Try
var xPos = $(this).css('left');
var yPos = $(this).css('top');
...instead.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745328793a4622779.html
评论列表(0条)