I am trying to make a slider. But for some reason i can't get the logic right. I know once in past i have gotten it right. But i don't remember it now.
Updated http://jsfiddle.net/techsin/9QqNa/2/
var slider= $('.slider'), mY, dY, clicking=false;
slider.mousedown(function(e){
mY = e.pageY, clicking = true;
})
$(window).mousemove(function(e){
if (!clicking) return;
e.preventDefault();
dY= e.offsetY-mY;
mY +=dY;
console.log(e);
slider.css('top','+='+dY);
}).mouseup(removeit);
function removeit(){
clicking=false;
}
Problems Include: Updated - Need to stop at above and bottom limits.
Just had a quick look at your code, simply change the follow line:
dY= e.offsetY-mY;
to
dY= e.pageY-mY;
this should do
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.