小编Wil*_*llD的帖子

svg stroke-dashoffset 的百分比值的基础是什么

https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/Stroke-dashoffset

根据上面的链接,lines-dashoffset css 属性接受百分比。

百分比是多少的值?

我预计它是路径的总长度。但在一些实验中似乎并非如此。

在这里我尝试从 0% 到 100% 进行动画处理...

.circles {
    stroke-dasharray: 50%;
    animation-name: dashingRotation;
    animation-duration: 2s;
    animation-iteration-count: infinite;
}

@keyframes dashingRotation {
    0%     {stroke-dashoffset: 0%;}
    50%    {stroke-dashoffset: 100%;}
    100%   {stroke-dashoffset: 100%}
}
Run Code Online (Sandbox Code Playgroud)

完整代码: https: //jsfiddle.net/tssn40yL/

...但是破折号并没有占据一半的圆圈,并且动画也没有完全围绕。

那么这个百分比有什么参考意义呢?

css svg

5
推荐指数
1
解决办法
6530
查看次数

使用 .classLIst 将类添加到已经具有该类的元素是否有任何危害

这个问题的答案(addClass to an element already with that class?)表明,当使用 jQuery 时,如果你.addClass('foo')在一个已经有foo.

我很好奇 的element.classList方法也是如此.add

特别是我有一个函数update(),每当更新范围滑块时都会调用该函数。这可能在一秒钟内发生多次。根据传递给update()我的值,向元素添加和删除某些类。

如果该值连续落在某个范围内,我最终会一遍又一遍地添加相同的类。

我的问题是我是否可以允许 elem.classList.add('foo')在一秒钟内运行 50 次而不会对用户体验、内存、处理器使用等产生任何负面影响。这是可以接受的做法吗?

谢谢。

javascript css

5
推荐指数
1
解决办法
1593
查看次数

vitest 测试等待 vue3 组件中 onMounted 回调的异步完成

我正在使用 Vitest,并希望等待组件中 onMounted 生命周期挂钩中的几个模拟提取完成:

我的测试:

import { mount } from '@vue/test-utils';
import HelloWorld from './HelloWorld.vue';
import { mockGet } from 'vi-fetch';
import 'vi-fetch/setup';

mockGet('api/welcome-message').willResolve('Welcome message from vitest');
mockGet('api/players').willResolve(['Mario', 'Luigi']);


test('the players have been rendered', async () => {
  const wrapper = mount(HelloWorld);

  const lastPlayer = await wrapper.findAll('.player');
  expect(lastPlayer).toHaveLength(2);
});
Run Code Online (Sandbox Code Playgroud)

我的组件脚本:

<script setup lang="ts">
import { onMounted, ref } from 'vue';

const apiMessage = ref('');
const players = ref<string[]>([]);


onMounted(async () => {
  const fetchMessage = fetch('api/welcome-message')
    .then((res) => res.text())
    .then((message: …
Run Code Online (Sandbox Code Playgroud)

async-await vue.js vuejs3 vite vitest

4
推荐指数
1
解决办法
1万
查看次数

firebase CLI 无法识别“firebase init”的当前目录

我正在学习有关 Ionic Angular 的教程,现在已经到了讲师让我将代码发布到 Firebase Hosting 的地步。首先,我使用 NPM 来安装 Firebase CLI。然后我被指示使用该firebase init命令。问题是 CLI 似乎无法识别在我的终端中选择的当前目录。

我跑:cd /Users/MyUserName/myProjectsFolder/myProject/ 然后我跑firebase init,它显示:

您即将在此目录中初始化 Firebase 项目:

/用户/我的用户名

当我希望它阅读时:

您即将在此目录中初始化 Firebase 项目:

/Users/MyUserName/myProjectsFolder/myProject

一点谷歌搜索找到了这个页面:https : //firebase.google.com/docs/cli/

其中包括这段话:

要初始化新的项目目录,请将终端中的目录更改为所需的项目目录并运行:firebase init

基于此,我希望我采取的步骤工作。

我很迷惑。有没有人遇到过这种行为?任何人都可以想出一种方法让 CLI 按预期运行吗?

谢谢。

firebase firebase-tools

2
推荐指数
1
解决办法
1万
查看次数

在给定N个范围的情况下,以编程方式确定值是否在一个范围内

假设我有一个看起来像这样的数组:

const points = [ .1, .2, .25, .6, .72, .9 ]
Run Code Online (Sandbox Code Playgroud)

这些值中的每一个都代表一条线上的点/停止点。我的目标是要有一个函数,该函数返回输入值所在的范围(两个相邻数组值之间的空间)的索引。

例如,如果我放入.3函数,则将返回,3因为.3介于.25和之间,.6并且这是数组定义的第4个范围。请注意,我考虑-infinity.1第一(隐含的)范围。

到目前为止,我已经提出了:

function whichRange(input){
    if(input < points[0]) {
        return 0;
    }
    else if( input >= points[0] && input < points[1]){
        return 1;
    }
    else if( input >= points[1] && input < points[2]){
        return 2;
    }
    else if( input >= points[2] && input < points[3]){
        return 3;
    }
    else if( input >= points[3] && …
Run Code Online (Sandbox Code Playgroud)

javascript

2
推荐指数
1
解决办法
45
查看次数

使用vanilla js脚本模拟更改事件以将文本输入到react textarea中

我知道这不是“反应方式”或任何其他版本的理想。但是情况超出了我的控制范围,我需要找到解决方法或“破解”。话虽如此....

我正在寻找一种以编程方式将文本内容输入到<textarea>作为反应组件一部分呈现的元素中的方法。问题是我需要从 react 应用程序外部执行此操作。React 应用程序是由其他人编写、编译、缩小和交付的。

<textarea>有一个id分配ATTR,这样我就可以查询它并设置其.value足够容易。然而,我的真正目标是影响react 应用程序的状态也就是说,使用文本区域的绑定onChange处理程序使我的字符串进入呈现文本区域的组件的状态。

到目前为止,我已尝试首先:设置<textarea>. 第二:触发“更改”事件。但到目前为止,这并没有触发onChange回调。

为了让您了解我实际上在谈论什么,我创建了这个挑战的最小示例

这是来自该stackblitz的代码:

反应部分。 这代表我无法控制的反应应用程序。

import React, { Component } from 'react';
import { render } from 'react-dom';

class App extends Component {

  constructor(props){
    super(props)

    this.state = {
      message: "" //I would like this be the value of what I place into the text area
    }
  }

  changeHandler = e => { …
Run Code Online (Sandbox Code Playgroud)

javascript dom-events reactjs

2
推荐指数
1
解决办法
977
查看次数

如何处理模板文字中的无关空白

如何处理多行模板文字生成的字符串以排除通过遵循任何/所有 JS 代码缩进创建的所有空格。

我使用正则表达式替换来删除第一个测试字符串中的前导空格。但是,如果字符串是 HTML,它具有我想保留的缩进结构,该怎么办?

//problem: includes a lot of white space


    if(true){
        const aString = `This string
                        is multiline
                        and indented to match
                        the surrounding 
                        JS code`
        console.log(aString)
    }


//what I have tried

    if(true){
        const aString = `This string
                        is multiline
                        and indented to match
                        the surrounding 
                        JS code`
        
        const newString = aString.replace(/\n[ \t]+/g, " \n")
        console.log(newString)
    }
    
//but what about this

    if(true){
        const aString = `<div class="hello">
                            <div class="inner">
                               <span>Some text</span>
                            </div>
                         </div>`
        
        const newString = aString.replace(/\n[ \t]+/g, …
Run Code Online (Sandbox Code Playgroud)

javascript regex template-literals

2
推荐指数
1
解决办法
1583
查看次数

当设置为 ie &gt;= 11 时,带有 @rollup/plugin-babel 的 vite/rollup 不会去除模板文字反引号

尝试在库模式下使用 Vite 将 ES6.js文件编译为将在 Internet Explorer 11 中运行的捆绑 ES5.js文件。在我的实际应用程序中,有几个文件使用 ESM 导入/导出,但是我已经验证我可以重现单个简化示例文件的问题。我将在下面介绍。

这是我的配置:

//vite.config.js
const path = require('path');
const { defineConfig } = require('vite');
import { babel } from '@rollup/plugin-babel';

module.exports = defineConfig({
  esbuild: false,
  plugins: [
    babel({
      babelHelpers: 'bundled',
      presets: [['@babel/preset-env', { targets: { browsers: 'defaults, ie >= 11' } }]],
    }),
  ],
  build: {
    outDir: 'javascript',
    lib: {
      entry: path.resolve(__dirname, 'js-src/index.js'),
      name: 'MyLib',
      fileName: (format) => 'my-lib.js',
    },
  },
});
Run Code Online (Sandbox Code Playgroud)

测试文件:

const aWord = 'World'; …
Run Code Online (Sandbox Code Playgroud)

javascript internet-explorer babeljs template-literals vite

2
推荐指数
1
解决办法
4177
查看次数

docker 从 docker-compose.yml 构建自定义镜像

我有一个设置,其中有一个 Dockerfile 和一个 docker-compose.yml。

Dockerfile:

# syntax=docker/dockerfile:1
FROM php:7.4
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer
RUN docker-php-ext-install mysqli pdo pdo_mysql
RUN apt-get -y update
RUN apt-get -y install git
COPY . .
RUN composer install
Run Code Online (Sandbox Code Playgroud)

YML 文件:

version: '3.8'
services:
  foo_db:
    image: mysql:5.7
    environment:
      - MYSQL_ROOT_PASSWORD=foo
      - MYSQL_DATABASE=foo
  foo_app:
    image: foo_php
    platform: linux/x86_64
    restart: unless-stopped
    ports:
      - 8000:8000
    links:
      - foo_db
    environment:
      - DB_CONNECTION=mysql
      - DB_HOST=foo_db
      - DB_PORT=3306
      - DB_PASSWORD=foo
    command: sh -c "php artisan serve --host=0.0.0.0 --port=8000"
  foo_phpmyadmin:
    image: phpmyadmin
    links: …
Run Code Online (Sandbox Code Playgroud)

docker dockerfile docker-compose docker-image

1
推荐指数
1
解决办法
2018
查看次数

pip 错误:找不到与 google-api-python-client 匹配的分发版

我正在遵循这篇关于 Firebase 和 Google App Engine 的博文中概述的步骤

https://firebase.googleblog.com/2017/03/how-to-schedule-cron-jobs-with-cloud.html

当我尝试运行时:

pip install -t lib -r requirements.txt
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

Could not fetch URL https://pypi.python.org/simple/google-api-python-client/: There was a problem confirming the ssl certificate: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:661) - skipping
  Could not find a version that satisfies the requirement google-api-python-client (from -r requirements.txt (line 1)) (from versions: )
No matching distribution found for google-api-python-client (from -r requirements.txt (line 1))
You are using pip version 9.0.1, however version 9.0.3 is available.
You should …
Run Code Online (Sandbox Code Playgroud)

pip google-api-python-client

0
推荐指数
1
解决办法
9140
查看次数

Array.splice() 在数组文字上以一种方式运行,在保存为 const 的数组上以另一种方式运行

所以这会很短。

我有以下代码:

const foo = [1,2,3,4].splice(2, 1);
console.log("foo", foo);
// [3]

const bar = [1,2,3,4]
bar.splice(2, 1);
console.log("bar", bar);
// [1, 2, 4]
Run Code Online (Sandbox Code Playgroud)

正如你所看到的,如果你运行它(至少在 Chrome 中) foo 控制台到一个具有单个值的数组, 3其中 bar 控制台到一个包含所有项目的三项数组, 3

造成这种差异的原因是什么?

javascript arrays

0
推荐指数
1
解决办法
185
查看次数