我有一個圖像,它有一個黃色的按鈕。我想用黃色按鈕作爲手柄,這樣當我上下拖動黃色div
時,圖像會跟着上下移動。我的圖像被約束爲y軸,所以同樣按鈕必須被約束爲y軸。拖動圖像作爲圖像的句柄按鈕
這裏是一個小提琴: http://jsfiddle.net/michelm/9Vwzp/
和jQuery代碼:
$(function(){
$(".headerimage").css('cursor','s-resize');
var y1 = $('.container').height();
var y2 = $('img').height();
$("img").draggable({
scroll: false,
axis: "y",
handle: "div.button" // this is not working
drag: function(event, ui) {
if(ui.position.top >= 0)
{
ui.position.top = 0;
}
else if(ui.position.top <= y1 - y2)
{
ui.position.top = y1 - y2;
}
},
stop: function(event, ui) {
//####
}
});
});