Bla*_*bam 8 html javascript css jquery bxslider
以下代码段应该很好地演示了这个问题:
(function ($) {
$('.bxslider').each(function() {
var bxid = $(this).attr("data-bxid");
var bx = $(this).bxSlider({
auto: false,
autoStart: false
});
});
})(jQuery);Run Code Online (Sandbox Code Playgroud)
/* Styles */
#before, #after {
width:350px;
height:350px;
background-color:#ccf;
}
/* BXSlider */
.bx-wrapper {
position: relative;
margin-bottom: 60px;
padding: 0;
*zoom: 1;
-ms-touch-action: pan-y;
touch-action: pan-y;
}
.bx-wrapper img {
max-width: 100%;
display: block;
}
.bxslider {
background-color:#eee;
margin: 0;
padding: 0;
/*fix flickering when used background-image instead of <img> (on Chrome)*/
-webkit-perspective: 1000;
}
ul.bxslider {
list-style: none;
width:100%;
}
ul.bxslider li {
width:100%;
}
.bx-viewport {
/* fix other elements on the page moving (in Chrome) */
-webkit-transform: translateZ(0);
}Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bxslider/4.2.15/jquery.bxslider.min.js"></script>
<div id="before"></div>
<ul class="bxslider">
<li><p>If you touch me vertically ...<img src="https://via.placeholder.com/500x350"></li>
<li>... I want to scroll down normally ...<img src="https://via.placeholder.com/500x250"></li>
<li>... but nothing happens <img src="https://via.placeholder.com/500x450"></li>
</ul>
<div id="after"></div>Run Code Online (Sandbox Code Playgroud)
在浏览器窗口的开发人员工具中,尝试通过触摸在正在运行的代码段中向下滚动 - 这是不可能的.然而,这不是一个选项,因为全屏横向bxSlider访问者正在失去完全浏览网站的能力 - 这是不可接受的!
bxSlider提供以下设置:
touchEnabled:false
Run Code Online (Sandbox Code Playgroud)
然而,这也不是一个选择,因为智能手机访客真的应该能够用手指向右/向左切换幻灯片.
因此,我需要一种可能性:
不幸的是,我没有找到bxslider设置的任何组合如何实现这一点.你知道一个解决方案(最好不修改bxslider核心文件本身)吗?
小智 4
我编辑了jquery.bxslider.jsonTouchStart中的函数。
只需复制以下代码并将其替换为原始 onTouchStart 函数代码(从 1103 行开始):
var onTouchStart = function(e) {
// watch only for left mouse, touch contact and pen contact
// touchstart event object doesn`t have button property
if (e.type !== 'touchstart' && e.button !== 0) {
return;
}
var lastScrollTop = 0;
$(window).scroll(function(event){
var st = $(this).scrollTop();
if (st > lastScrollTop){ } else { e.preventDefault(); }
});
//disable slider controls while user is interacting with slides to avoid slider freeze that happens on touch devices when a slide swipe happens immediately after interacting with slider controls
slider.controls.el.addClass('disabled');
if (slider.working) {
slider.controls.el.removeClass('disabled');
} else {
// record the original position when touch starts
slider.touch.originalPos = el.position();
var orig = e.originalEvent,
touchPoints = (typeof orig.changedTouches !== 'undefined') ? orig.changedTouches : [orig];
var chromePointerEvents = typeof PointerEvent === 'function';
if (chromePointerEvents) {
if (orig.pointerId === undefined) {
return;
}
}
// record the starting touch x, y coordinates
slider.touch.start.x = touchPoints[0].pageX;
slider.touch.start.y = touchPoints[0].pageY;
if (slider.viewport.get(0).setPointerCapture) {
slider.pointerId = orig.pointerId;
slider.viewport.get(0).setPointerCapture(slider.pointerId);
}
// store original event data for click fixation
slider.originalClickTarget = orig.originalTarget || orig.target;
slider.originalClickButton = orig.button;
slider.originalClickButtons = orig.buttons;
slider.originalEventType = orig.type;
// at this moment we don`t know what it is click or swipe
slider.hasMove = false;
// on a "touchmove" event to the viewport
slider.viewport.on('touchmove MSPointerMove pointermove', onTouchMove);
// on a "touchend" event to the viewport
slider.viewport.on('touchend MSPointerUp pointerup', onTouchEnd);
slider.viewport.on('MSPointerCancel pointercancel', onPointerCancel);
}
};
Run Code Online (Sandbox Code Playgroud)
编辑(小提琴):https://jsfiddle.net/Blackbam/sk2ve907/2/
用于测试: https: //jsfiddle.net/Blackbam/sk2ve907/2/show