简体   繁体   English

旋转反转滚动(180d)

[英]Invert scroll on rotate(180d)

Having a small problem. 有一个小问题。 (Refer to fiddle) I've got a container in my project that has been rotated 180 deg, with a container inside that has been rotated another 180 back to the original state. (请参阅小提琴)我的项目中有一个已旋转180度的容器,其中的一个容器又旋转了180度回到原始状态。

I need to invert the scroll. 我需要反转滚动。 How would i go about this? 我将如何处理?

Dont mind wasting your time with a method, that reverts the basic setup. 不要介意浪费时间来恢复基本设置。 The basic setup has to stay. 基本设置必须保留。

http://jsfiddle.net/vavxy36s/ http://jsfiddle.net/vavxy36s/

Description of fiddle: "Start" marks the initial string and "end" ofcourse the last one. 小提琴的描述:“开始”标记初始字符串,“结束”标记最后一个字符串。 If you try scrolling you will realize, that it's inverted as to how one would normally scroll. 如果尝试滚动,您会发现,它在正常滚动方式上是相反的。

.class1 {
    height: 200px;
    background-color: blue;
    color: white;
    width: 100px;
    overflow-y: scroll;
    overflow-x: hidden;
    direction: rtl;
    -webkit-transform: rotate(180deg);
}
.class2 {
    direction: ltr;
    -webkit-transform: rotate(180deg);
}

EDIT: Just mousewheel scroll, has to be inverted. 编辑:只是滚轮滚动,必须反转。

Edit: Your original setup has different behaviors in Chrome and in [IE & Firefox]. 编辑:您的原始设置在Chrome和[IE&Firefox]中具有不同的行为。 In Chrome, the scroll is already inverted, but in FF and IE, the scroll remains normal. 在Chrome中,滚动已经反转,但在FF和IE中,滚动保持正常。 My solution reverts it in both cases, but the behaviors remain different across browsers. 我的解决方案在两种情况下都将其还原,但是行为在浏览器之间仍然不同。

You could add these styles: 您可以添加以下样式:

/* ...
   Your original styles
   ...
*/

.class1 {
    overflow: hidden;
    position: relative;
}
.class2 {
    position: absolute;
    bottom: 0;
}

And then, using jQuery, modify the bottom CSS property of .class2 : 然后,使用jQuery修改.class2bottom CSS属性:

var scrollPos = 0,
    diff      = $('.class2').height() - $('.class1').height();


$('.class1').on('mousewheel', function(e) {
    scrollPos = Math.min(
                         0,
                         Math.max(
                                  -diff,
                                  scrollPos + e.originalEvent.wheelDelta
                        )
                );

    $('.class2').css('bottom', scrollPos);
});

JS Fiddle Demo JS小提琴演示

You could use the mousewheel library to catch and invert the scroll movement. 您可以使用鼠标滚轮库捕获并反转滚动运动。

$(".class1").mousewheel(function(event) {

  event.preventDefault();

  this.scrollTop -= (event.deltaY * event.deltaFactor * -1);

});

You can view a demo here: http://jsfiddle.net/fduu20df/1/ 您可以在此处查看演示: http : //jsfiddle.net/fduu20df/1/

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

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