简体   繁体   English

jQuery滑块:平滑单击动画

[英]Jquery slider: smooth click animation

jquery sliders contain a "animate" opton that when set to "true" will slide the handle into postion when the slider bar is clicked. jQuery滑块包含一个“动画”选项,单击该滑块时,将其设置为“ true”时,会将手柄滑入位置。

Im using my slider to scroll the content in another div, creating a similar eeffect as the one on the apple website. 我使用滑块在另一个div中滚动内容,从而产生了与apple网站上类似的效果。 http://www.apple.com/mac/ http://www.apple.com/mac/

the problem is that when i click the sliderbar it smoothly animates the handle but not the other div. 问题是,当我单击滑块时,它会平滑地使手柄动画,但不会使另一个div动画。 i have the other div scrolling on the "slide" and "change" events. 我在“幻灯片”和“更改”事件上有另一个div滚动。 any ideas how i can achieve smooth scrolling for the other div? 任何想法,我如何才能使其他div平滑滚动?

Thanks in advance, oh gods of jQuery. 在此先感谢jQuery之神。

my code: 我的代码:

var list = $('.sliderGallery ul');

$('.slider').slider({
    min:0,
    max:1500,
    animate: true,
    slide: function(event, ui) { list.css('left', '-' + ui.value + 'px'); },
    change: function(event, ui) { list.css('left', '-' + ui.value + 'px'); }
});

It's been a while since I used JavaScript but as far as I remember jQuery you can try to do the same thing you are already doing but using animation effect. 自从我使用JavaScript以来已经有一段时间了,但就我记得jQuery而言,您可以尝试做已经做过的事情,但是要使用动画效果。 Try this: 尝试这个:

var list = $('.sliderGallery ul');

$('.slider').slider({
    min:0,
    max:1500,
    animate: true,
    slide: function(event, ui) { list.animate({'left': '-' + ui.value + 'px'}, 'normal'); },
    change: function(event, ui) { list.animate({'left': '-' + ui.value + 'px'}, 'normal'); }
});

This code may not work right away but it hopefully might serve as a starting point. 该代码可能无法立即生效,但希望可以作为起点。 Here's a link to this function documentation: animate( params, [duration], [easing], [callback] ) in Effects/animate . 这是此功能文档的链接: Effects / animate中的animate(params,[duration],[easing],[callback])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM