gpt4 book ai didi

javascript - 如何在翻书前后居中翻书

转载 作者:行者123 更新时间:2023-11-28 08:00:13 24 4
gpt4 key购买 nike

我正在尝试使这本翻页书在页面上自动居中,以便在翻动或不翻动时保持居中。我使用了 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com