首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用Spin.js使微调器工作?

如何使用Spin.js使微调器工作?
EN

Stack Overflow用户
提问于 2012-09-03 19:22:37
回答 5查看 47.1K关注 0票数 8

大家好,

我是JavaScript的新手,在互联网上进行了大量的研究,并尝试实现一个旋转器失败后,我决定向您请教。

我正在使用Spin.js ( http://fgnass.github.com/spin.js/#v1.2.6 )。它看起来是一个很棒的工具,但我就是不能让它工作。我的问题是我哪里做错了?我真的搞不懂。任何帮助都将不胜感激。非常感谢。

下面是我的一段代码:

代码语言:javascript
复制
   <script src="Scripts/Spin.js" type="text/javascript"></script>

    <script type="text/javascript">
           function spinnerInit() {
               var opts = {
                   lines: 13, // The number of lines to draw
                   length: 7, // The length of each line
                   width: 4, // The line thickness
                   radius: 10, // The radius of the inner circle
                   corners: 1, // Corner roundness (0..1)
                   rotate: 0, // The rotation offset
                   color: '#000', // #rgb or #rrggbb
                   speed: 1, // Rounds per second
                   trail: 60, // 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: 'auto', // Top position relative to parent in px
                   left: 'auto', // Left position relative to parent in px
                   visibility: true
               };

               var target = document.getElementById('spinnerContainer');
               //target.style.display = "block";
               var spinner = new Spinner(opts).spin(target);
           }
       </script>

      <script type="text/javascript">
           $(document).ready(function () {
               $('#btnPerformSave').click(function () {
                   spinnerInit();
               });
           });
       </script>

     <div id="spinnerContainer" class="spinner" style="width: 100%; height: 150%;
           position: absolute; z-index: 100; background-color: Gray;
           left: 0; top:  0; bottom: 0;right: 0">
       </div>
EN

回答 5

Stack Overflow用户

发布于 2012-09-03 19:56:20

尝试替换

代码语言:javascript
复制
var target = document.getElementById('spinnerContainer');
var spinner = new Spinner(opts).spin(target);

使用

代码语言:javascript
复制
$('#spinnerContainer').after(new Spinner(opts).spin().el);

您需要将spin方法创建的html元素附加到dom

下面是一个开始使用http://jsfiddle.net/5CQJP/1/的示例

票数 16
EN

Stack Overflow用户

发布于 2013-01-27 13:58:11

我不确定这个问题是否得到了回答,但对于那些仍在寻找答案的人:

我发现我需要将javascript移到spinnerContainer目录下。我相信如果你把javascript放在一个onload事件中,这也是可行的。下面是我所做的:

代码语言:javascript
复制
<div id="spinnerContainer" class="spinner" style="width:100px;height:100px;background-color: Gray;">
</div>
<script src="Scripts/Spin.js" type="text/javascript"></script>
<script type="text/javascript">
    var opts = {
      lines: 13, // The number of lines to draw
      length: 7, // The length of each line
      width: 4, // The line thickness
      radius: 10, // The radius of the inner circle
      corners: 1, // Corner roundness (0..1)
      rotate: 0, // The rotation offset
      color: '#000', // #rgb or #rrggbb
      speed: 1, // Rounds per second
      trail: 60, // 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: 'auto', // Top position relative to parent in px
      left: 'auto' // Left position relative to parent in px
    };
    var target = document.getElementById('spinnerContainer');
    var spinner = new Spinner(opts).spin(target);
</script>
票数 10
EN

Stack Overflow用户

发布于 2016-11-03 03:34:15

这是我的答案。效果很好。

代码语言:javascript
复制
//Declare Script
<script src="Scripts/spin.js" type="text/javascript"></script>


 <button  id="btnSearchClick">Search</button>

//Displays Loading Spinner
<div id="loading">
    <div id="loadingcont">
        <p id="loadingspinr">
        </p>
    </div>
</div>



<script type="text/javascript">
     //On button click load spinner and go to another page
     $("#btnSearchClick").click(function () {  
        //Loads Spinner
        $("#loading").fadeIn();
        var opts = {
            lines: 12, // The number of lines to draw
            length: 7, // The length of each line
            width: 4, // The line thickness
            radius: 10, // The radius of the inner circle
            color: '#000', // #rgb or #rrggbb
            speed: 1, // Rounds per second
            trail: 60, // Afterglow percentage
            shadow: false, // Whether to render a shadow
            hwaccel: false // Whether to use hardware acceleration
        };
        var trget = document.getElementById('loading');
        var spnr = new Spinner(opts).spin(trget);

        //Go another page.
        window.location.href = "http://www.example.com/";
   });
 </script>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12246854

复制
相关文章

相似问题

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