站长资源网络编程

环形加载进度条封装(Vue插件版和原生js版)

整理:jimmy2026/7/29浏览2
简介本文实例为大家分享了环形加载进度条封装代码,供大家参考,具体内容如下1、效果预览2、用到的知识主要利用SVG的stroke-dasharray和stroke-dashoffset这两个属性。在看下面文章之前,你需要了解sv</div> <div class="news_infos"><div id="MyContent"><p>本文实例为大家分享了环形加载进度条封装代码,供大家参考,具体内容如下</p> <p><strong>1、效果预览</strong></p> <p><a href="javascript:;" onclick="showimg('/UploadFiles/2021-04-02/201912484155161.jpg');"><img src="/UploadFiles/2021-04-02/201912484155161.jpg" alt="环形加载进度条封装(Vue插件版和原生js版)" onmousewheel="return bbimg(this)" onload="javascript:resizepic(this)" border="0"/></a></p> <p><strong>2、用到的知识</strong></p> <p>主要利用SVG的stroke-dasharray和stroke-dashoffset这两个属性。<br> 在看下面文章之前,你需要了解</p> <div class="htmlcode"> <pre class="brush:xhtml;"> <!DOCTYPE html> <html> <head> <title>svg demo</title> <style type="text/css"> #line{ transition: all 2s; stroke-dasharray:300,320; stroke-dashoffset:300; } svg:hover #line{ stroke-dashoffset: 0; } #circle{ transition: all 2s; stroke-dasharray:314,314; stroke-dashoffset:314; } svg:hover #circle{ stroke-dashoffset:0; } </style> </head> <body> <h3>线段区域</h3> <svg width="100%" height="40" > <line id="line" x1="30" y1="30" x2="300" y2="30" stroke-width="20" stroke="red" /> </svg> <h3>圆区域</h3> <svg width="200" height="200" viewBox="0 0 200 200"> <circle id="circle" cx="100" cy="80" r="50" fill="gray" stroke-width="5" stroke="green" /> </svg> </body> </html></pre> </div> <p><strong>3、使用</strong></p> <p>有两种方式,一种是直接安装即可使用,一种需要封装。选一种适合自己的即可。</p> <p>(1)、安装插件</p> <p>安装Vue插件</p> <div class="htmlcode"> <pre class="brush:js;"> npm install loading-vue-component</pre> </div> <p>使用</p> <div class="htmlcode"> <pre class="brush:js;"> // main.js import loading from 'loading-vue-component' Vue.use(loading)</pre> </div> <div class="htmlcode"> <pre class="brush:js;"> // app.vue <template> <div id="app"> <loading :radius="20" :progress="progress" :stroke="2" :color='color'></loading> </div> </template> <script> export default { name: 'app', data() { return { progress: 0,color:'#1989fa'} } } </script> </pre> </div> <p>(2)、封装插件</p> <p>Vue版</p> <div class="htmlcode"> <pre class="brush:xhtml;"> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>loading</title> <style> html, body { display: flex; align-items: center; justify-content: center; height: 100%; position: relative; margin: 0; padding: 0; } circle { transition: stroke-dashoffset 0.15s; transform: rotate(-90deg); transform-origin: 50% 50%; } .txt{ font-size: 14px; text-align: center; } .loading{ padding:40vh; } </style> </head> <body> <div id="example"></div> </body> <script src="/UploadFiles/2021-04-02/vue.js"> <p>原生js版</p> <div class="htmlcode"> <pre class="brush:xhtml;"> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>progress</title> <style> html, body { background-color: #333; display: flex; align-items: center; justify-content: center; height: 100%; position: relative; } .progress-ring__circle { transition: 0.35s stroke-dashoffset; transform: rotate(-90deg); transform-origin: 50% 50%; } input { position: fixed; top: 10px; left: 10px; width: 80px; } </style> </head> <body> <svg class="progress-ring" width="120" height="120"> <circle class="progress-ring__circle" stroke="white" stroke-width="4" fill="transparent" r="52" cx="60" cy="60" /> </svg> <input value="35" type="number" step="5" min="0" max="100" placeholder="progress"> </body> <script type="text/javascript"> var circle = document.querySelector('circle'); var radius = circle.r.baseVal.value; var circumference = radius * 2 * Math.PI; circle.style.strokeDasharray = `${circumference} ${circumference}`; circle.style.strokeDashoffset = `${circumference}`; function setProgress(percent) { const offset = circumference - percent / 100 * circumference; circle.style.strokeDashoffset = offset; } const input = document.querySelector('input'); setProgress(input.value); input.addEventListener('change', function(e) { if (input.value < 101 && input.value > -1) { setProgress(input.value); } }) </script> </html></pre> </div> <p>以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。</p></div> </div> </div> <div class="share"> </div> <div class="nextinfo"> <p>上一篇:<a href="/3g/1/82570.html" title="Vue实现图片与文字混输效果">Vue实现图片与文字混输效果</a></p> <p>下一篇:<a href="/3g/1/82572.html" title="element-ui 远程搜索组件el-select在项目中组件化的实现代码">element-ui 远程搜索组件el-select在项目中组件化的实现代码</a></p> </div> <div class="otherlink"> <h2>最新资源</h2> <ul> <li><a href="/3g/1/623703.html" title="群星《奔赴!万人现场 第2期》[FLAC/分轨]">群星《奔赴!万人现场 第2期》[FLAC/分轨]</a></li> <li><a href="/3g/1/623702.html" title="群星《奇妙浪一夏 (上海迪士尼度假区音乐">群星《奇妙浪一夏 (上海迪士尼度假区音乐</a></li> <li><a href="/3g/1/623701.html" title="群星《奇妙浪一夏 (上海迪士尼度假区音乐">群星《奇妙浪一夏 (上海迪士尼度假区音乐</a></li> <li><a href="/3g/1/623700.html" title="【古典音乐】詹姆斯·高威《季节》1993[WA">【古典音乐】詹姆斯·高威《季节》1993[WA</a></li> <li><a href="/3g/1/623699.html" title="贝拉芳蒂《卡里普索之王》SACD[WAV+CUE]">贝拉芳蒂《卡里普索之王》SACD[WAV+CUE]</a></li> <li><a href="/3g/1/623698.html" title="小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE">小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE</a></li> <li><a href="/3g/1/623697.html" title="群星《欢迎来到我身边 电影原声专辑》[32">群星《欢迎来到我身边 电影原声专辑》[32</a></li> <li><a href="/3g/1/623696.html" title="群星《欢迎来到我身边 电影原声专辑》[FL">群星《欢迎来到我身边 电影原声专辑》[FL</a></li> <li><a href="/3g/1/623695.html" title="雷婷《梦里蓝天HQⅡ》 2023头版限量编号低">雷婷《梦里蓝天HQⅡ》 2023头版限量编号低</a></li> <li><a href="/3g/1/623694.html" title="群星《2024好听新歌42》AI调整音效【WAV分">群星《2024好听新歌42》AI调整音效【WAV分</a></li> </ul> </div> </div> <div class="sidebar"> </div> <div class="sidebar"> 友情链接:<a href="http://www.imxmx.com/" title="杰晶网络" target="_blank">杰晶网络</a> <a href="/" title="DDR爱好者之家" target="_blank">DDR爱好者之家</a> <a href="http://www.nqxw.com/" title="南强小屋" target="_blank">南强小屋</a> <a href="http://www.paidiu.com/" title="黑松山资源网" target="_blank">黑松山资源网</a> <a href="http://www.dyhadc.com/" title="白云城资源网" target="_blank">白云城资源网</a> <a href="/sitemap1.xml">站点地图</a> <a href="/sitemap.xml">SiteMap</a> </div> </article> <footer> <p>Design by <a href="http://m.ddrfans.com">DDR爱好者之家</a> <a href="http://m.ddrfans.com">http://m.ddrfans.com</a></p> </footer> <script src="/images3g/nav.js"></script> <script type="text/javascript"> jQuery.noConflict(); jQuery(function() { var elm = jQuery('#left_flow2'); var startPos = jQuery(elm).offset().top; jQuery.event.add(window, "scroll", function() { var p = jQuery(window).scrollTop(); jQuery(elm).css('position', ((p) > startPos) ? 'fixed' : ''); jQuery(elm).css('top', ((p) > startPos) ? '0' : ''); }); }); </script> </body> </html>