Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在AnythingSlider中应用滑动_Javascript_Jquery_Video_Youtube_Anythingslider - Fatal编程技术网

Javascript 如何在AnythingSlider中应用滑动

Javascript 如何在AnythingSlider中应用滑动,javascript,jquery,video,youtube,anythingslider,Javascript,Jquery,Video,Youtube,Anythingslider,我使用的是官方文件中提到的,但它在嵌入式youtube视频上不起作用。问题是youtube视频实际上是内置HTML5和嵌入式视频的iFrame。因此,在视频上滑动不会与iframe之外的内容注册。最简单的解决方案是在视频上放置一个覆盖层,让它只覆盖视频。问题是你不能点击视频本身让它播放,你必须使用控制 在中,覆盖覆盖视频并使控件可见(向滑动覆盖css添加背景:#f00;以查看它)。控件的高度为40像素,因此您将看到叠加的高度考虑到了这一点 这是css(此演示的滑块大小为300 x 200): 这

我使用的是官方文件中提到的,但它在嵌入式youtube视频上不起作用。

问题是youtube视频实际上是内置HTML5和嵌入式视频的iFrame。因此,在视频上滑动不会与iframe之外的内容注册。最简单的解决方案是在视频上放置一个覆盖层,让它只覆盖视频。问题是你不能点击视频本身让它播放,你必须使用控制

在中,覆盖覆盖视频并使控件可见(向滑动覆盖css添加
背景:#f00;
以查看它)。控件的高度为40像素,因此您将看到叠加的高度考虑到了这一点

这是css(此演示的滑块大小为300 x 200):

这是更新的初始化代码:

$('#slider').anythingSlider({

    // Callback when the plugin finished initializing
    onInitialized: function(e, slider) {

        var time = 1000, // allow movement if < 1000 ms (1 sec)
            range = 50,  // swipe movement of 50 pixels triggers the slider
            x = 0, t = 0, touch = "ontouchend" in document,
            st = (touch) ? 'touchstart' : 'mousedown',
            mv = (touch) ? 'touchmove' : 'mousemove',
            en = (touch) ? 'touchend' : 'mouseup';

        $('<div class="swipe-overlay"></div>')
            .appendTo(slider.$window)
            .bind(st, function(e){
                // prevent image drag (Firefox)
                e.preventDefault();
                t = (new Date()).getTime();
                x = e.originalEvent.touches ? e.originalEvent.touches[0].pageX : e.pageX;
            })
            .bind(en, function(e){
                t = 0; x = 0;
            })
            .bind(mv, function(e){
                e.preventDefault();
                var newx = e.originalEvent.touches ? e.originalEvent.touches[0].pageX : e.pageX,
                r = (x === 0) ? 0 : Math.abs(newx - x),
                // allow if movement < 1 sec
                ct = (new Date()).getTime();
                if (t !== 0 && ct - t < time && r > range) {
                    if (newx < x) { slider.goForward(); }
                    if (newx > x) { slider.goBack(); }
                    t = 0; x = 0;
                }
            });
    }

});
$(“#滑块”)。任意滑块({
//插件完成初始化时回调
初始化:功能(e,滑块){
var time=1000,//如果<1000毫秒(1秒),允许移动
范围=50,//滑动50像素会触发滑块
文件中的x=0,t=0,touch=“ontouchend”,
st=(触摸)“‘触摸启动’:‘鼠标向下’,
mv=(触摸)“‘触摸移动’:‘鼠标移动’,
en=(触摸)“‘触摸端’:‘鼠标’;
$('')
.appendTo(滑块$window)
.绑定(st,函数(e){
//防止图像拖动(Firefox)
e、 预防默认值();
t=(新日期()).getTime();
x=e.originalEvent.touchs?e.originalEvent.touchs[0]。pageX:e.pageX;
})
.bind(en,函数(e){
t=0;x=0;
})
.绑定(mv,功能(e){
e、 预防默认值();
var newx=e.originalEvent.touchs?e.originalEvent.touchs[0]。pageX:e.pageX,
r=(x==0)?0:Math.abs(newx-x),
//如果移动时间小于1秒,则允许
ct=(新日期()).getTime();
如果(t!==0&&ct-t范围){
if(newxx){slider.goBack();}
t=0;x=0;
}
});
}
});
$('#slider').anythingSlider({

    // Callback when the plugin finished initializing
    onInitialized: function(e, slider) {

        var time = 1000, // allow movement if < 1000 ms (1 sec)
            range = 50,  // swipe movement of 50 pixels triggers the slider
            x = 0, t = 0, touch = "ontouchend" in document,
            st = (touch) ? 'touchstart' : 'mousedown',
            mv = (touch) ? 'touchmove' : 'mousemove',
            en = (touch) ? 'touchend' : 'mouseup';

        $('<div class="swipe-overlay"></div>')
            .appendTo(slider.$window)
            .bind(st, function(e){
                // prevent image drag (Firefox)
                e.preventDefault();
                t = (new Date()).getTime();
                x = e.originalEvent.touches ? e.originalEvent.touches[0].pageX : e.pageX;
            })
            .bind(en, function(e){
                t = 0; x = 0;
            })
            .bind(mv, function(e){
                e.preventDefault();
                var newx = e.originalEvent.touches ? e.originalEvent.touches[0].pageX : e.pageX,
                r = (x === 0) ? 0 : Math.abs(newx - x),
                // allow if movement < 1 sec
                ct = (new Date()).getTime();
                if (t !== 0 && ct - t < time && r > range) {
                    if (newx < x) { slider.goForward(); }
                    if (newx > x) { slider.goBack(); }
                    t = 0; x = 0;
                }
            });
    }

});