Javascript 制作spin.js spinner';s相对于目标div的位置
目前jQuery spin.js微调器具有定位它的选项 我以前使用过以下配置:Javascript 制作spin.js spinner';s相对于目标div的位置,javascript,jquery,parent,spin.js,Javascript,Jquery,Parent,Spin.js,目前jQuery spin.js微调器具有定位它的选项 我以前使用过以下配置: // set up spin.js vars var opts = { lines: 13, // The number of lines to draw length: 5, // The length of each line width: 2, // The line thickness radius:5, // The r
// set up spin.js vars
var opts = {
lines: 13, // The number of lines to draw
length: 5, // The length of each line
width: 2, // The line thickness
radius:5, // The radius of the inner circle
corners: 1, // Corner roundness (0..1)
rotate: 58, // The rotation offset
direction: 1, // 1: clockwise, -1: counterclockwise
color: '#fff', // #rgb or #rrggbb or array of colors
speed: 0.9, // Rounds per second
trail: 100, // Afterglow percentage
shadow: false, // Whether to render a shadow
hwaccel: false, // Whether to use hardware acceleration
className: 'mySpinner', // The CSS class to assign to the spinner
zIndex: 2e9, // The z-index (defaults to 2000000000)
top: '50%', // Top position relative to parent
left: '50%' // Left position relative to parent
};
// show a spinner in place of the icon
var target = document.getElementById('testdiv');
var spinner = new Spinner(opts).spin(target);
$(target).data('mySpinner', spinner);
但是,该位置显示其相对于其父对象的位置
因此,目前的结构是:
<div id="container">
<div id="testdiv">
</div>
<div>
微调器将在包含的div中居中,而不是在目标div中居中。是否有办法解决此问题?如果您仍在寻找解决方案,我想您可以使用
position:relative
使其工作,如下所示:
.mySpinner {
position: relative !important;
}
这样,微调器将在testdiv
中居中