亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

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

使用反應/減少照片長度的淡出效果

使用反應/減少照片長度的淡出效果

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

1 回答

?
守著一只汪

TA貢獻1872條經驗 獲得超4個贊

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

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

圖片.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 平滑地應用淡出效果:


main.css


.picture {

? opacity: 1;

? transition: opacity 0.2s linear;

}


.picture.fadeOut {

? opacity: 0;

}

其他建議:

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

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

  • 每個圖像都應該有一個alt屬性


查看完整回答
反對 回復 2023-08-05
  • 1 回答
  • 0 關注
  • 111 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號