鼠标移动时滑动的Jquery滑块 [英] Jquery slider that slides while mouse move
问题描述
我正在寻找一个jquery滑块脚本,该脚本能够在移动鼠标时左右滑动.有人知道那种脚本吗?我想达到类似这一个的效果,但应水平滚动而不是垂直滚动.
I'm looking for a jquery slider script that is able to right-left slide while I'm moving my mouse. Anyone knows that kind of script? I want to achieve an effect like this one but it should be scrolled horizontal, not vertical.
推荐答案
您的意思是这样的.使用 jQuery UI Slider 是非常基本的事情.我将处理程序附加到mousemove事件,该事件仅计算滑块的值(基于鼠标坐标的值).
Do you mean something like this. It's a very basic thing that uses the jQuery UI Slider. I attach a handler to the mousemove event that just calculates what the value should be for the slider (based on the value of the mouse coordinates).
$(function() {
var range = 100,
sliderDiv = $("#slider");
// Activate the UI slider
sliderDiv.slider({
min: 0,
max: range
});
// Number of tick marks on slider
var position = sliderDiv.position(),
sliderWidth = sliderDiv.width(),
minX = position.left,
maxX = minX + sliderWidth,
tickSize = sliderWidth / range;
$(this).mousemove(function(e) {
// If within the slider's width, follow it along
if (e.pageX >= minX && e.pageX <= maxX) {
var val = (e.pageX - minX) / tickSize;
sliderDiv.slider("value", val);
}
});
});
说实话,这不是很棒的代码,但是它确实给出了一个基本示例,说明如何使用jQuery UI滑块以及如何使用代码设置值.
It's not fantastic code, to be honest, but it does give a basic example of how to use the jQuery UI slider and how to set the value using code.
示例: http://jsfiddle.net/jonathon/qAMWQ/
这篇关于鼠标移动时滑动的Jquery滑块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!