jquery 滑块不适用于 jquery-1.6!
此滑块代码适用于旧版本的 jquery,例如 jquery-1.5。但当我尝试将它与最新版本的 jquery - jquery-1.6 集成时,它无法正常工作。
您可以在此处尝试 - 当您沿着滑块滑动时,内容不会滚动。当您前后拖动滑块时,内容应沿着滑块滚动。
这是一些代码,
function init_scrollbar ()
{
//scrollpane parts
scroll_frame = $('#scroll-frame'); // scroll-frame
scroll_content = $('#scroll-content'); // scroll-content
scroll_location_pixel = 0;
original_location_scroll_handle = 0;
original_width_scroll_content = scroll_content.width();
scrollbar = $('#content-slider').slider({
min: 0,
animate: true,
create: on_scrollcreate,
change: on_scrollchange,
slide: on_scrollslide
});
}
我认为这是事件 slide
不起作用,这是代码,
function on_scrollslide(event, ui)
{
var scroll_maximum = scroll_content.width() - scroll_frame.width();
scroll_frame.attr({scrollLeft: ui.value * (scroll_maximum / 100) });
}
知道我做错了什么吗?你能告诉我如何修复它吗?
谢谢。
This slider code works fine with older version of jquery, such as jquery-1.5. But it does not work properly when I tried to intergrate it with the latest version of jquery - jquery-1.6.
You can try it here - the content does not scroll when you along the slider. The content should be scrolled along the slider when you drag and move it forward and backward.
Here is some of the code,
function init_scrollbar ()
{
//scrollpane parts
scroll_frame = $('#scroll-frame'); // scroll-frame
scroll_content = $('#scroll-content'); // scroll-content
scroll_location_pixel = 0;
original_location_scroll_handle = 0;
original_width_scroll_content = scroll_content.width();
scrollbar = $('#content-slider').slider({
min: 0,
animate: true,
create: on_scrollcreate,
change: on_scrollchange,
slide: on_scrollslide
});
}
I think it is the event slide
does not work, here it is the code,
function on_scrollslide(event, ui)
{
var scroll_maximum = scroll_content.width() - scroll_frame.width();
scroll_frame.attr({scrollLeft: ui.value * (scroll_maximum / 100) });
}
Any idea what have I done wrong? can you tell me how to fix it?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对于 jQuery 1.6:
这是一个工作小提琴。
For jQuery 1.6:
Here is a working fiddle.
jQuery 现在可以通过新的
.prop()
正确区分属性和属性方法。在
on_scrollslide
函数中,将scroll_frame.attr({
) 更改为scroll_frame.prop({
:jQuery is now properly distinguishing between attributes and properties with its new
.prop()
method.In the
on_scrollslide
function, changescroll_frame.attr({
toscroll_frame.prop({
:我认为你应该忽略1.6版本,直接进入1.6.1。
根据 jQuery 博客:
从 1.5.2 更新到 1.6.1 时,您不必更改任何属性代码。
来源:
http://blog.jquery.com/
I think you should ignore version 1.6 and directly go to 1.6.1.
Per the jQuery blog:
When updating from 1.5.2 to 1.6.1, you should not have to change any attribute code.
Source:
http://blog.jquery.com/