我试图将第一行的黑色文本块淡化为最后一行的浅灰色.我注意到亚马逊用它们的产品描述做了这件事.我试着查看CSS代码,我在那里看不到任何东西,我怀疑它是用javascript实现的.
我的问题是:如何在我自己的文本块上模拟类似的垂直淡化效果?
这是有效的 YAML:
item:
wooden wand:
damage: 5
Run Code Online (Sandbox Code Playgroud)
如果不是,我该如何使其有效?我正在尝试创建一个键,它的值是包含/对wooden wand的对象。damage5
我有两个一维数组,a并且b. a有值且b为空。的长度a是偶数。我想从 中删除所有其他值a并将它们移动到b,按照它们放置在 中的顺序相同a。
var a = [1, 2, 3, 4, 5, 6], b = [];
Run Code Online (Sandbox Code Playgroud)
变成
var a = [1, 3, 5], b = [2, 4, 6];
Run Code Online (Sandbox Code Playgroud)
我认为这filter可以解决问题,但我对其性能不太满意,因为平均长度为a300-400。
b = a.filter((i, idx) => {
return idx % 2 == 0;
});
a = a.filter((i, idx) => {
return idx % 2 == 1;
});
Run Code Online (Sandbox Code Playgroud)
我也一直在查看 lodash,看看该库是否有任何可以帮助我的东西,唯一接近我正在寻找的功能是_.chunk(array, \[size=1\]).
我感谢所有帮助我找到更好、更快的方法来做到这一点的帮助。
所以我尝试使用YouTube 的播放器 API,它对于前 2 或 3 个实例效果很好。然后它崩溃并停止工作,拒绝渲染我传递给它的任何视频。
它似乎每秒在控制台中抛出此错误两次,每 500 毫秒一次。
www-widgetapi.js:100 无法在“DOMWindow”上执行“postMessage”:提供的目标源(“ https://www.youtube.com ”)与收件人窗口的源(“ http://localhost ”)不匹配)。
这是代码
let ajax_url = "http://localhost/scripts/ajax";
let newest_video;
let player;
$(document).ready(() => {
loadVideo();
});
function onPlayerReady(event) {
event.target.playVideo();
}
function onPlayerStateChange(event) {
if(event.data === 0) {
loadVideo(true);
}
}
function loadVideo(next = false) {
$.ajax({
url: ajax_url + '/get_link.php',
data: {
"selection": (next ? "not_first" : "first")
},
type: 'GET',
error: function(data) {
alert(data);
},
success: function(data) {
newest_video = data;
let …Run Code Online (Sandbox Code Playgroud) Node.JS 10.15,无服务器,lambda,在本地调用
样品A)的工作原理:
export async function main(event) {
const marketName = marketIdToNameMap[event.marketId];
const marketObject = marketDirectory[marketName];
const marketClient = await marketObject.fetchClient();
const marketTime = await marketObject.getTime(marketClient);
console.log(marketTime);
}
Run Code Online (Sandbox Code Playgroud)
样本B),这有效:
export function main(event) {
const marketName = marketIdToNameMap[event.marketId];
const marketObject = marketDirectory[marketName];
marketObject.fetchClient().then((marketClient)=>{
marketObject.getTime(marketClient).then((result) => {
console.log('<---------------> marker 1 <--------------->');
console.log(result);
});
});
}
Run Code Online (Sandbox Code Playgroud)
样本C),但这不是:
export async function main(event) {
const marketName = marketIdToNameMap[event.marketId];
const marketObject = marketDirectory[marketName];
const marketClient = await marketObject.fetchClient();
console.log('<---------------> marker 1 <--------------->');
marketObject.getTime(marketClient).then((result) => {
console.log('<---------------> …Run Code Online (Sandbox Code Playgroud) 在 React Native 中,视图元素接受一个style在驼峰式对象中使用 CSS 属性名称的属性:
const styleObj = {
width: 200,
marginTop: 10
}
Run Code Online (Sandbox Code Playgroud)
元素也接受这样的样式对象数组:
<MyComponent style={[ styleObj, styleProp && styleProp ]} />
Run Code Online (Sandbox Code Playgroud)
我有几个抽象的按钮组件,它们依赖于共享的基本按钮界面。为简单起见:
interface IButton {
style?: ViewStyle | ViewStyle[] // <-- ViewStyle is exported by react native, and contains all the allowed style properties for a View component
}
Run Code Online (Sandbox Code Playgroud)
我认为这个定义就足够了,但我遇到了一些我难以理解的问题。
我有一个DropDown组件,它呈现一个Button. 当我使用 style 道具时,我收到一个错误:
<Button
style={[
{
backgroundColor: backgroundColor || COLORS.lightRed,
borderRadius: 3,
height: 44,
width: '100%',
},
style && style, …Run Code Online (Sandbox Code Playgroud) 我有一个承诺,当我为特定用户获取数据时,我使用它来设置状态。下面是代码:
getUserUsername = (): string => {
const { match } = this.props;
return match.params.username;
};
onFetchUser = () =>
getUser(this.getUserUsername())
.then(username => {
if (this.hasBeenMounted) {
this.setState({
user: username.data // The error is here.
});
}
})
.catch((errorResponse: HttpResponseObj | null = null) => {
if (this.hasBeenMounted) {
this.setState({
isLoading: false,
user: null,
errorMessage: errorResponse
});
}
});
Run Code Online (Sandbox Code Playgroud)
但我收到这个 TS 错误说:
Property 'data' does not exist on type 'void | AxiosResponse<IUser>'.
Property 'data' does not exist on type 'void'.ts(2339) …Run Code Online (Sandbox Code Playgroud) 我想立即启动一个无头的 Chrome 浏览器,做一些自动化操作,然后在做其他事情之前把它变成可见的。
使用 Puppeteer 是否可以做到这一点,如果可以,你能告诉我怎么做吗?如果不是,是否有任何其他浏览器自动化框架或库可以做到这一点?
到目前为止,我已经尝试了以下但没有奏效。
const browser = await puppeteer.launch({'headless': false});
browser.headless = true;
const page = await browser.newPage();
await page.goto('https://news.ycombinator.com', {waitUntil: 'networkidle2'});
await page.pdf({path: 'hn.pdf', format: 'A4'});
Run Code Online (Sandbox Code Playgroud) 我有一个 Node.js 模块,如下所示:
module.exports = function()
{
// linked dependencies
this.dependency1 = 'dependency1/dependency1.exe';
this.dependency2 = 'dependency2/dependency2.exe';
this.dependency3 = 'dependency3/dependency3.exe';
}
Run Code Online (Sandbox Code Playgroud)
我希望开发人员能够轻松编辑依赖项相对于模块文件本身的位置。但是,在使用模块时,当前工作目录process.cwd()通常与模块目录不同,因此这些路径无法正确解析。path.resolve()似乎只相对于当前工作目录工作,并且没有任何参数来允许自定义参考点/路径。
我已经能够通过以下方式解析路径,但我发现它丑陋且麻烦,它应该比这更容易:
this.ResolvePath = function(p)
{
var cwd = process.cwd();
process.chdir(path.dirname(module.filename));
var resolvedPath = path.resolve(p);
process.chdir(cwd);
return resolvedPath;
}
Run Code Online (Sandbox Code Playgroud)
有没有更干净的方法来做到这一点?我觉得path.relative()应该保留解决方案,但我找不到让它发挥作用的方法。也许将多个path.relative()s 链接在一起可能会起作用,但我现在无法思考它是如何工作的。
我正在使用useReducer钩子来管理我的状态,但在我的上下文提供程序中读取更新状态似乎有问题。
我的上下文提供程序负责获取一些远程数据并根据响应更新状态:
import React, { useEffect } from 'react';
import useAppState from './useAppState';
export const AppContext = React.createContext();
const AppContextProvider = props => {
const [state, dispatch] = useAppState();
const initialFunction = () => {
fetch('/some_path')
.then(res => {
dispatch({ type: 'UPDATE_STATE', res });
});
};
const otherFunction = () => {
fetch('/other_path')
.then(res => {
// why is `state.stateUpdated` here still 'false'????
dispatch({ type: 'DO_SOMETHING_ELSE', res });
});
}
};
const actions = { initialFunction, otherFunction }; …Run Code Online (Sandbox Code Playgroud) javascript ×9
node.js ×3
reactjs ×3
typescript ×2
arrays ×1
async-await ×1
axios ×1
css ×1
es6-promise ×1
lodash ×1
puppeteer ×1
react-hooks ×1
react-native ×1
serverless ×1
yaml ×1
youtube-api ×1