add rtl support

Conflicts:
	src/perfect-scrollbar.js
This commit is contained in:
ahspw 2014-04-17 07:31:57 +02:00 committed by Hyunje Alex Jun
parent 4a8e8066ab
commit b8231ecd79
2 changed files with 50 additions and 3 deletions

30
examples/rtl.html Normal file
View File

@ -0,0 +1,30 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>perfect-scrollbar example</title>
<link href="../src/perfect-scrollbar.css" rel="stylesheet">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="../src/jquery.mousewheel.js"></script>
<script src="../src/perfect-scrollbar.js"></script>
<style>
.contentHolder { position:relative; margin:0px auto; padding:0px; width: 600px; height: 400px; overflow: hidden; }
.contentHolder .content { background-image: url('./azusa.jpg'); width: 1280px; height: 720px; }
.spacer { text-align:center }
html { direction: rtl; }
</style>
<script>
jQuery(document).ready(function ($) {
"use strict";
$('#Default').perfectScrollbar();
});
</script>
</head>
<body>
<div id="Default" class="contentHolder">
<div class="content">
</div>
</div>
</body>
</html>

View File

@ -101,6 +101,7 @@
scrollbarYRight = parseInt($scrollbarYRail.css('right'), 10), scrollbarYRight = parseInt($scrollbarYRail.css('right'), 10),
isScrollbarYUsingRight = scrollbarYRight === scrollbarYRight, // !isNaN isScrollbarYUsingRight = scrollbarYRight === scrollbarYRight, // !isNaN
scrollbarYLeft = isScrollbarYUsingRight ? null: parseInt($scrollbarYRail.css('left'), 10), scrollbarYLeft = isScrollbarYUsingRight ? null: parseInt($scrollbarYRail.css('left'), 10),
isRtl = $this.css('direction') === "rtl",
eventClassName = getEventClassName(); eventClassName = getEventClassName();
var updateContentScrollTop = function (currentTop, deltaY) { var updateContentScrollTop = function (currentTop, deltaY) {
@ -159,7 +160,12 @@
}; };
var updateScrollbarCss = function () { var updateScrollbarCss = function () {
var scrollbarXStyles = {left: $this.scrollLeft(), width: containerWidth, display: scrollbarXActive ? "inherit": "none"}; var scrollbarXStyles = {width: containerWidth, display: scrollbarXActive ? "inherit": "none"};
if (isRtl) {
scrollbarXStyles.left = $this.scrollLeft() + containerWidth - contentWidth;
} else {
scrollbarXStyles.left = $this.scrollLeft();
}
if (isScrollbarXUsingBottom) { if (isScrollbarXUsingBottom) {
scrollbarXStyles.bottom = scrollbarXBottom - $this.scrollTop(); scrollbarXStyles.bottom = scrollbarXBottom - $this.scrollTop();
} else { } else {
@ -168,12 +174,22 @@
$scrollbarXRail.css(scrollbarXStyles); $scrollbarXRail.css(scrollbarXStyles);
var scrollbarYStyles = {top: $this.scrollTop(), height: containerHeight, display: scrollbarYActive ? "inherit": "none"}; var scrollbarYStyles = {top: $this.scrollTop(), height: containerHeight, display: scrollbarYActive ? "inherit": "none"};
if (isScrollbarYUsingRight) { if (isScrollbarYUsingRight) {
if (isRtl) {
scrollbarYStyles.right = contentWidth - $this.scrollLeft() - scrollbarYRight - $scrollbarY.outerWidth();
} else {
scrollbarYStyles.right = scrollbarYRight - $this.scrollLeft(); scrollbarYStyles.right = scrollbarYRight - $this.scrollLeft();
}
} else {
if (isRtl) {
scrollbarYStyles.left = $this.scrollLeft() + containerWidth * 2 - contentWidth - scrollbarYLeft - $scrollbarY.outerWidth();
} else { } else {
scrollbarYStyles.left = scrollbarYLeft + $this.scrollLeft(); scrollbarYStyles.left = scrollbarYLeft + $this.scrollLeft();
} }
}
$scrollbarYRail.css(scrollbarYStyles); $scrollbarYRail.css(scrollbarYStyles);
$scrollbarX.css({left: scrollbarXLeft, width: scrollbarXWidth}); $scrollbarX.css({left: scrollbarXLeft, width: scrollbarXWidth});
$scrollbarY.css({top: scrollbarYTop, height: scrollbarYHeight}); $scrollbarY.css({top: scrollbarYTop, height: scrollbarYHeight});
}; };
@ -563,6 +579,7 @@
scrollbarYHeight = scrollbarYHeight =
scrollbarYTop = scrollbarYTop =
scrollbarYRight = null; scrollbarYRight = null;
isRtl = null;
}; };
var ieSupport = function (version) { var ieSupport = function (version) {