我檢出了source code for react-slick,找到下面顯示的代碼部分;
if (this.props.responsive) {
var breakpoints = this.props.responsive.map(breakpt => breakpt.breakpoint);
breakpoints.sort((x, y) => x - y);
breakpoints.forEach((breakpoint, index) => {
var bQuery;
if (index === 0) {
bQuery = json2mq({minWidth: 0, maxWidth: breakpoint});
} else {
bQuery = json2mq({minWidth: breakpoints[index-1], maxWidth: breakpoint});
}
this.media(bQuery,() => {
this.setState({breakpoint: breakpoint});
});
});
// Register media query for full screen. Need to support resize from small to large
var query = json2mq({minWidth: breakpoints.slice(-1)[0]});
this.media(query,() => {
this.setState({breakpoint: null});
});
}
我從這個代碼明白什麼是react-slick實際上是用兩個min-width and max-width
但排序給出斷點後,第一個要去總是得到min-width: 0
。
所以這裏是你可以做的事情。它有點破解,但我認爲它能完成這項工作。
const settings = {
dots: true,
infinite: true,
speed: 500,
slidesToShow: 1,
slidesToScroll: 1,
responsive: [
{
breakpoint: 768,
},
{
breakpoint: 10000, // a unrealistically big number to cover up greatest screen resolution
settings: 'unslick'
}
]
};
這段代碼做的是,它創造2項媒體,
@media only screen and (min-width: 0px) and (max-width: 768px) { ... } // empty
@media only screen and (min-width: 768px) and (max-width: 10000px) { ... } // disables slick
希望它能幫助。
要說清楚,如果寬度大於768px,你想禁用react-slick? – bennygenel
是的。目前,響應浮油僅對響應中的設置產生最大寬度。 – henhen