Phi*_*lip 2 jquery direction carousel
我如何知道旋转木马在活动中的方向onBeforeChange.右或左?
$('.foo').slick
infinite: false
onBeforeChange: (e) ->
if right
do_this()
if left
do_that()
Run Code Online (Sandbox Code Playgroud)
小智 6
beforeChange事件使您可以访问currentSlide和nextSlide值.
它也适用于无限滑块.
所以,代码是:
$(".some-element").on('beforeChange', function (event, slick, currentSlide, nextSlide) {
if (Math.abs(nextSlide - currentSlide) == 1) {
direction = (nextSlide - currentSlide > 0) ? "right" : "left";
}
else {
direction = (nextSlide - currentSlide > 0) ? "left" : "right";
}
});
Run Code Online (Sandbox Code Playgroud)
你必须询问该元素是否具有 dir 属性并设置为 rtl
var attr = $('.foo').attr('dir');
if (typeof attr !== typeof undefined && attr !== false && attr === 'rtl') {
do_this()
} else {
do_that()
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6847 次 |
| 最近记录: |