简体   繁体   English

光标位置进行自定义光标更改-Royalslider

[英]custom cursor change based on cursor position - Royalslider

I'm using royalslider. 我正在使用Royalslider。 I have a function which allows navigation depending on cursor position. 我有一个允许根据光标位置进行导航的功能。

}).data('royalSlider');
           slider.ev.on('rsSlideClick', function(e, origEvent) {
           var width = jQuery('.royalSlider').data('royalSlider').width;

           if (origEvent.pageX < (width/2)) {
                slider.prev();
                $('.rsOverflow').css({
                      'cursor': 'url(images/prevg.png), default'
           });

                } else {
                slider.next();
                $('.rsOverflow').css({
                       'cursor': 'url(images/nextg.png), default'
               });

              };
            });
           });

How can I modify this so that cursors change on hover - not just after click. 我如何修改此设置,以便光标在悬停时发生变化-不仅仅是单击之后。 Thanks 谢谢

That would work if you change the css at that point trough javascript (jQuery). 如果您通过javascript(jQuery)更改了CSS,就可以了。 For my solution you would hav to implement jQuery in your html before you use your following script: 对于我的解决方案,您可能需要在使用以下脚本之前在html中实现jQuery:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

Than the code below would change the cursor 比下面的代码会更改光标

 var slider = $('#full-width-slider').royalSlider({ autoHeight: true, ///// more options ///// navigateByClick: false, prefix: 'image-' }, }).data('royalSlider'); slider.ev.on('rsSlideClick', function(e, origEvent) { var width = jQuery('.royalSlider').data('royalSlider').width; if (origEvent.pageX < (width/2)) { slider.prev(); // change css to prevg.png $('.rsOverflow').css({ "cursor" : "url('images/prevg.png'), auto !important;" }); } else { slider.next(); // change css to nextg.png $('.rsOverflow').css({ "cursor" : "url('images/nextg.png'), auto !important;" }); }; }); }); 

Now that I saw your Example. 现在,我看到了您的示例。 I can't see a simple way of using the existing functions. 我看不到使用现有功能的简单方法。 Now you could try this: 现在,您可以尝试以下操作:

 var mContainer = $('body'), left = $(window).width() / 2, x, y; $(window).mousemove(function(evt){ x = (evt.pageX - mContainer.offset().left) + $(window).scrollLeft(); if(x < left) { $('.rsOverflow').css({ "cursor" : "url('images/prevg.png'), auto !important;" }); } else { $('.rsOverflow').css({ "cursor" : "url('images/nextg.png'), auto !important;" }); } }); 

I am calculating the offset position of the cursor on the X-Axis. 我正在计算光标在X轴上的偏移位置。 Now you can check if the cursor is on the left part of the site or on the right part. 现在,您可以检查光标是在站点的左侧还是右侧。 An can change the cursor accordingly. 可以相应地更改光标。 Hope that helps! 希望有帮助!

I believe the best way is just to use two overlaying divs and remove them on touch as Yuri suggested. 我认为最好的方法就是使用两个重叠的div,并按照Yuri的建议将其移除。 As the hover event is not written into the code its difficult to detect. 由于悬停事件未写入代码中,因此很难检测到。

<script type="text/javascript">
jQuery(function($){
if(typeof ontouchstart !== 'undefined'){
    $('.prev1, .next1').remove();
}
});
</script>

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

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