第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用反應(yīng)/減少照片長度的淡出效果

使用反應(yīng)/減少照片長度的淡出效果

qq_遁去的一_1 2023-08-05 20:49:38
如何為每張照片卡實現(xiàn)淡出效果,然后在淡出效果后減少照片的長度?這是鏈接: https: //codesandbox.io/s/pedantic-herschel-f12gq。我找到了解決方案,但當我按下每張照片時,該解決方案不起作用。有誰知道這些問題嗎?
查看完整描述

1 回答

?
守著一只汪

TA貢獻1872條經(jīng)驗 獲得超4個贊

嘗試這樣:https:?//codesandbox.io/s/serene-pine-ckph1

在React中,修改組件的方式是根據(jù)它的props/state。單擊圖片容器時更新狀態(tài),然后使用它來添加類。

圖片.js

import React, { Component } from "react";

import "../css/utilities.css";

import "../css/main.css";


class Pictures extends Component {

? constructor(props) {

? ? super(props);


? ? this.state = {

? ? ? fadeOut: false

? ? };


? ? this.fadeOut = this.fadeOut.bind(this);

? }


? fadeOut() {

? ? this.setState({ fadeOut: true }, function () {

? ? ? setTimeout(function () {

? ? ? ? document.getElementById("length").innerText--;

? ? ? }, 200);

? ? });

? }


? render() {

? ? console.log(this.props.picture);

? ? const { title, thumbnailUrl } = this.props.picture;

? ? return (

? ? ? <div

? ? ? ? className={

? ? ? ? ? "picture card container" + (this.state.fadeOut ? " fadeOut" : "")

? ? ? ? }

? ? ? ? onClick={(event) => this.fadeOut(event)}

? ? ? >

? ? ? ? <img src={thumbnailUrl} alt="" />

? ? ? ? <h1 className="title">{title}</h1>

? ? ? </div>

? ? );

? }

}

export default Pictures;

然后該類使用 CSS 平滑地應(yīng)用淡出效果:


main.css


.picture {

? opacity: 1;

? transition: opacity 0.2s linear;

}


.picture.fadeOut {

? opacity: 0;

}

其他建議:

  • 上面的代碼代替 jsonPlaceholder.js 運行,以更好地遵循框架約定并僅使用 CSS 進行樣式設(shè)置

  • 在 HTML 中,每個idid="picture"屬性必須是唯一的,因此如果有超過 1 個圖片元素,則無法設(shè)置

  • 每個圖像都應(yīng)該有一個alt屬性


查看完整回答
反對 回復(fù) 2023-08-05
  • 1 回答
  • 0 關(guān)注
  • 121 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號