本文介绍了使用turn.js进行垂直翻转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在应用程序中使用turn.js,并且想要实现类似于 http的垂直翻转://pageflip-books.com/documentation-configuration.php -VerticalMode
I am using turn.js in my application and would like to implement the vertical flipping similar to http://pageflip-books.com/documentation-configuration.php - VerticalMode
谁能告诉我,如何在turn.js中实现垂直翻转?
Can anyone let me know, how can I implement the vertical flipping in turn.js?
推荐答案
1.将每个页面旋转-90度
2.将整本书(日历)旋转90度
3.从垂直页面水平方向更改鼠标(触摸)事件坐标
1. rotate each page -90deg
2. rotate the whole book(calendar) 90deg
3. change mouse(touch) event coordinate from vertical page horizontal one
_translateCoordinate: function(e) {
if (!e) {
return e;
}
var data = this.data().f;
var pos = data.parent.offset();
var oldX = e.pageX - pos.left;
var oldY = e.pageY - pos.top;
var newX = oldY + pos.left;
var newY = this.height() - oldX + pos.top;
return {
pageX: newX,
pageY: newY
};
},
turn.js坐标翻译用法
_eventMove: function(e) {
var data = this.data().f;
if (!data.disabled) {
e = (isTouch) ? e.originalEvent.touches : [e];
if (data.corner) {
var pos = data.parent.offset();
var posInNewCoordinate =
flipMethods._translateCoordinate.call(this, e[0]); // here
data.corner.x = posInNewCoordinate.pageX - pos.left;
data.corner.y = posInNewCoordinate.pageY - pos.top;
_cornerActivated: function(e) {
if (e.originalEvent === undefined) {
return false;
}
e = (isTouch) ? e.originalEvent.touches : [e];
var posInNewCoordinate =
flipMethods._translateCoordinate.call(this, e[0]); // here
var data = this.data().f,
pos = data.parent.offset(),
width = this.width(),
height = this.height(),
c = {
x: Math.max(0, posInNewCoordinate.pageX - pos.left),
y: Math.max(0, posInNewCoordinate.pageY - pos.top)
},
的HTML
<!doctype html>
<html>
<head>
<script type="text/javascript" src="jquery-1.7.1.js"></script>
<script type="text/javascript" src="turn.js"></script>
<style type="text/css">
#calendar,
.calendar-wrapper {
transform-origin: 0% 0% 0px;
}
#calendar .turn-page {
background-image: url('paper-texture.png');
background-repeat: repeat;
}
.page-wrapper>.page {
height: 800px;
width: 600px;
transform-origin: 0% 0% 0px;
}
</style>
</head>
<body>
<div>
<div class="calendar-wrapper">
<div id="calendar">
<div class="page-wrapper">
<div class="page" style="background-image:url(pages/01.jpg);"></div>
</div>
<div class="page-wrapper">
<div class="page" style="background-image:url(pages/02.jpg);"></div>
</div>
<div class="page-wrapper">
<div class="page" style="background-image:url(pages/03.jpg);"></div>
</div>
<div class="page-wrapper">
<div class="page" style="background-image:url(pages/04.jpg);"></div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
$(window).ready(function() {
var $page = $('.page-wrapper>.page');
var $calendarWrapper = $('.calendar-wrapper');
var $pageWrapper = $('.page-wrapper');
var $calendar = $('#calendar');
var height = $page.height();
var width = $page.width();
$page.css('transform', `translate3d(0px, ${width}px, 0px) rotate(-90deg)`);
$calendarWrapper.height(width);
$calendarWrapper.width(height);
$calendarWrapper.css('transform', `translate3d(${width}px, 0px, 0px) rotate(90deg)`)
$pageWrapper.height(width);
$pageWrapper.width(height);
$calendar.height(width);
$calendar.width(height);
$calendar.turn({
display: 'single',
acceleration: true,
gradients: false,
gradients: !$.isTouch,
elevation: 50,
when: {
turned: function(e, page) {
/*console.log('Current view: ', $(this).turn('view'));*/
}
}
});
});
</script>
</body>
</html>
这篇关于使用turn.js进行垂直翻转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!