作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使这本翻页书在页面上自动居中,以便在翻动或不翻动时保持居中。我使用了 autoCenter
的 flip.js 文档,以及 $("#flipbook").turn("center");
但没有任何效果。有谁知道这是否可以做到?一个工作示例在下面的 fiddle 中:-
http://jsfiddle.net/kmturley/GGea5/1/
<div class="t">
<div class="tc rel">
<div class="book" id="book">
<div class="page"><img src="https://raw.github.com/blasten/turn.js/master/demos/magazine/pages/01.jpg" alt="" /></div>
<div class="page"><img src="https://raw.github.com/blasten/turn.js/master/demos/magazine/pages/02.jpg" alt="" /></div>
<div class="page"><img src="https://raw.github.com/blasten/turn.js/master/demos/magazine/pages/03.jpg" alt="" /></div>
<div class="page"><img src="https://raw.github.com/blasten/turn.js/master/demos/magazine/pages/04.jpg" alt="" /></div>
<div class="page"><img src="https://raw.github.com/blasten/turn.js/master/demos/magazine/pages/05.jpg" alt="" /></div>
<div class="page"><img src="https://raw.github.com/blasten/turn.js/master/demos/magazine/pages/06.jpg" alt="" /></div>
</div>
</div>
</div>
/*
* Turn.js responsive book
*/
/*globals window, document, $*/
(function () {
'use strict';
var module = {
ratio: 1.38,
init: function (id) {
var me = this;
// if older browser then don't run javascript
if (document.addEventListener) {
this.el = document.getElementById(id);
this.resize();
this.plugins();
// on window resize, update the plugin size
window.addEventListener('resize', function (e) {
var size = me.resize();
$(me.el).turn('size', size.width, size.height);
});
}
},
resize: function () {
// reset the width and height to the css defaults
this.el.style.width = '';
this.el.style.height = '';
var width = this.el.clientWidth,
height = Math.round(width / this.ratio),
padded = Math.round(document.body.clientHeight * 0.9);
// if the height is too big for the window, constrain it
if (height > padded) {
height = padded;
width = Math.round(height * this.ratio);
}
// set the width and height matching the aspect ratio
this.el.style.width = width + 'px';
this.el.style.height = height + 'px';
return {
width: width,
height: height
};
},
plugins: function () {
// run the plugin
$(this.el).turn({
gradients: true,
acceleration: true
});
// hide the body overflow
document.body.className = 'hide-overflow';
}
};
module.init('book');
}());
最佳答案
开始工作了。我错过了把这个自动居中放在代码的底部:-
plugins: function () {
// run the plugin
$(this.el).turn({
gradients: true,
acceleration: true,
autoCenter: true
});
// hide the body overflow
document.body.className = 'hide-overflow';
}
关于javascript - 如何在翻书前后居中翻书,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29818695/
我是一名优秀的程序员,十分优秀!