嗨开发人员遍布全球.
我想帮助一个简单,纯粹的Javascript (30行),JQuery free (和其他库)的 拖动控制滑块.
我一直在搜索几个月,发现很多脚本,但我不喜欢-Jquery因为大多数脚本需要4,5,6个javascript包括..我更喜欢较小的基本脚本..我喜欢调整它们就像我想要的我也可以从较小的脚本中精益求精.
我只需要一个简单的滑块,我可以用它:重新缩放图像,滚动页面,改变图像亮度(使用PHP)等.
我是新手javascript (2个月),这是我现在得到的...对不起的变量名称...
<script type="text/javascript">
_item = null;
mouse_x = 0;
drag_x = 0;
function move_init() {
document.onmousemove = _move;
document.onmouseup = _stop;
}
function _stop(){
_item = null;
}
function _move(e){
mouse_x = document.all ? window.event.clientX : e.pageX;
if(_item != null){
_item.style.left = (mouse_x - drag_x) + "px";
}
}
function _move_item(drag)
{
_item = drag;
drag_x = mouse_x - _item.offsetLeft;
}
move_init();
drag.onmousedown=_move_item(); // Agh.. did'nt figure …Run Code Online (Sandbox Code Playgroud)