首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将spin.js旋转器插入到div中?

将spin.js旋转器插入到div中?
EN

Stack Overflow用户
提问于 2014-05-24 10:17:30
回答 2查看 8.9K关注 0票数 4

刚刚找到了spin.js,它似乎是一个拯救生命的人。

问题是如何将旋转器插入到我的div中?

我有一个“跟随”按钮,当单击该按钮时,我会删除背景图像,并将其替换为loader.gif。

除了spin.js,我还能做同样的事情吗?

我想出了一个快活的例子:

http://jsfiddle.net/4XpHp/

我希望旋转器在红色方框内。

代码语言:javascript
复制
<div id="foo"></div>
<button id="spin"> Spin! </button>

var opts = {
  lines: 13, // The number of lines to draw
  length: 17, // The length of each line
  width: 8, // The line thickness
  radius: 21, // 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: 'spinner', // 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
};

$("#spin").click(function(){
  var target = document.getElementById('foo');
  var spinner = new Spinner(opts).spin(target);
});

#foo {
    width: 50px;
    height: 50px;
    background-color: #f00;
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-05-24 10:35:05

你只需要设置:

代码语言:javascript
复制
#foo {
   position: relative; //Added this
   width: 50px;
   height: 50px;
   background-color: #f00;
}

JsFiddle

这实际上是一个css问题。默认情况下,.spinner div被设置为position: absolute (您不能用css更改它,因为它是内联样式),这意味着它将位于https://developer.mozilla.org/en-US/docs/Web/CSS/position#Absolute_positioning的中间,我假设它是<body>标记(请在这里纠正我)。通过使#foo具有相对位置,它将成为一个定位祖先,旋转器将位于其中。

票数 6
EN

Stack Overflow用户

发布于 2014-05-24 10:43:15

我更新了你的小提琴让它做你想做的事。我只需调整一些配置值,以使顶部和左侧位置正确,然后调整旋转器本身的大小。

http://jsfiddle.net/4XpHp/2/

代码语言:javascript
复制
var opts = {
    lines: 10, // The number of lines to draw
    length: 7, // 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: 'spinner', // The CSS class to assign to the spinner
    zIndex: 2e9, // The z-index (defaults to 2000000000)
    top: '12%', // Top position relative to parent
    left: '6.5%' // Left position relative to parent
};
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23843817

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档