简体   繁体   English

当鼠标位于页面左侧或右侧时,移动Slick Slider画廊

[英]Move Slick Slider gallery when mouse is on left or right side of page

I am trying to get my gallery to move left when the mouse is on the left side of the page and move right when it is on the right side of the page. 我试图让我的画廊在鼠标位于页面左侧时向左移动,而当鼠标位于页面右侧时向右移动。 Here is the JSFiddle . 这是JSFiddle I tried to use the hover function but it doesn't work. 我试图使用悬停功能,但是它不起作用。 Mouseover seems to only work when you move the mouse over either on left or right side of the page and mousemove only seems to work when you move the mouse again. 鼠标悬停似乎仅在将鼠标移至页面左侧或右侧时有效,而鼠标移动似乎仅在再次移动鼠标时有效。 I would like it to still move (left or right) when the mouse is stationary (in either left or right side of page), or moved. 我希望鼠标静止不动(在页面的左侧或右侧)或移动时,它仍然可以移动(向左或向右)。

 $('.carousel-one').on('mouseover', function(e) { "use strict"; var mouseSide; if ((e.pageX - this.offsetLeft) < $(this).width() / 2) { $('.carousel-one').slickPrev(); } else { $('.carousel-one').slickNext(); } }); $('.carousel-one').slick({ arrows: true, infinite: true, speed: 500, slidesToShow: 1, centerMode: true, variableWidth: true, autoplay: true, autoplaySpeed: 2000 }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link href="https://cdn.jsdelivr.net/jquery.slick/1.3.15/slick.css" rel="stylesheet" /> <script src="https://cdn.jsdelivr.net/jquery.slick/1.3.15/slick.min.js"></script> <div class="carousel-one"> <div><img src="http://lorempixel.com/400/200" alt="Image three"></div> <div><img src="http://lorempixel.com/400/200" alt="Image one"></div> <div><img src="http://lorempixel.com/300/200" alt="Image two"></div> <div><img src="http://lorempixel.com/320/200" alt="Image four"></div> <div><img src="http://lorempixel.com/400/200" alt="Image five"></div> <div><img src="http://lorempixel.com/200/200" alt="Image seven"></div> <div><img src="http://lorempixel.com/300/200" alt="Image six"></div> </div> 

Set pauseOnHover: false, . 设置pauseOnHover: false, Hope this helps! 希望这可以帮助!

 $('.carousel-one').on('mouseover', function(e) { "use strict"; var mouseSide; if ((e.pageX - this.offsetLeft) < $(this).width() / 2) { $('.carousel-one').slickPrev(); } else { $('.carousel-one').slickNext(); } }); $('.carousel-one').slick({ arrows: true, infinite: true, pauseOnHover: false, speed: 500, slidesToShow: 1, centerMode: true, variableWidth: true, autoplay: true, autoplaySpeed: 2000 }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link href="https://cdn.jsdelivr.net/jquery.slick/1.3.15/slick.css" rel="stylesheet" /> <script src="https://cdn.jsdelivr.net/jquery.slick/1.3.15/slick.min.js"></script> <div class="carousel-one"> <div><img src="http://lorempixel.com/400/200" alt="Image three"></div> <div><img src="http://lorempixel.com/400/200" alt="Image one"></div> <div><img src="http://lorempixel.com/300/200" alt="Image two"></div> <div><img src="http://lorempixel.com/320/200" alt="Image four"></div> <div><img src="http://lorempixel.com/400/200" alt="Image five"></div> <div><img src="http://lorempixel.com/200/200" alt="Image seven"></div> <div><img src="http://lorempixel.com/300/200" alt="Image six"></div> </div> 

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

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