简体   繁体   English

按钮在第二次单击而不是 Reactjs 中的第一次单击时工作

[英]Button working on second click instead of first in Reactjs

I am i working on Reactjs/nextjs and right now in my page video with audio button,i want two things我正在研究 Reactjs/nextjs,现在在我的带有音频按钮的页面视频中,我想要两件事

1) I want "by default" there should be "bi bi-volume-mute" class in button instead of "bi bi-volume-down"
2) whenever i click on unmute ( after mute) then its not working with one click but if i click on second time then its working , in other words should be "mute or unmute" with single click

Here is my current code这是我当前的代码

function handleAudio() { 
    if (ref.current.paused) { 
        setMuted(false); 
        ref.current.play(); 
    } else { 
        setMuted(true); 
        ref.current.pause(); 
    }
}
    <buton onClick={handleAudio} className="customAudioPlayerButton">
            {!muted ? (
              <svg
                xmlns="http://www.w3.org/2000/svg"
                width="30"
                height="30"
                fill="currentColor"
                className="bi bi-volume-down"
                viewBox="0 0 16 16"
              >
                <path d="M9 4a.5.5 0 0 0-.812-.39L5.825 5.5H3.5A.5.5 0 0 0 3 6v4a.5.5 0 0 0 .5.5h2.325l2.363 1.89A.5.5 0 0 0 9 12V4zM6.312 6.39 8 5.04v5.92L6.312 9.61A.5.5 0 0 0 6 9.5H4v-3h2a.5.5 0 0 0 .312-.11zM12.025 8a4.486 4.486 0 0 1-1.318 3.182L10 10.475A3.489 3.489 0 0 0 11.025 8 3.49 3.49 0 0 0 10 5.525l.707-.707A4.486 4.486 0 0 1 12.025 8z" />
              </svg>
            ) : (
              <svg
                xmlns="http://www.w3.org/2000/svg"
                width="30"
                height="30"
                fill="currentColor"
                className="bi bi-volume-mute"
                viewBox="0 0 16 16"
              >
                <path d="M6.717 3.55A.5.5 0 0 1 7 4v8a.5.5 0 0 1-.812.39L3.825 10.5H1.5A.5.5 0 0 1 1 10V6a.5.5 0 0 1 .5-.5h2.325l2.363-1.89a.5.5 0 0 1 .529-.06zM6 5.04 4.312 6.39A.5.5 0 0 1 4 6.5H2v3h2a.5.5 0 0 1 .312.11L6 10.96V5.04zm7.854.606a.5.5 0 0 1 0 .708L12.207 8l1.647 1.646a.5.5 0 0 1-.708.708L11.5 8.707l-1.646 1.647a.5.5 0 0 1-.708-.708L10.793 8 9.146 6.354a.5.5 0 1 1 .708-.708L11.5 7.293l1.646-1.647a.5.5 0 0 1 .708 0z" />
              </svg>
            )}
          </buton>

can you please try this function.你能试试这个功能吗?

function handleAudio() { 
   if (muted) { 
     setMuted(false); 
     ref.current.play(); 
   } else { 
     setMuted(true); 
     ref.current.pause(); 
   } 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Javascript在第二个按钮上单击而不是第一个按钮 - Javascript working on second button click instead of first 单击事件仅在 ReactJS-Hooks 中的第一次和第二次有效 - on click event only working at first & second time in ReactJS-Hooks 按钮单击在ReactJs中不起作用 - Button click not working in ReactJs Javascript 按钮切换在第一次点击时不起作用,只有第二次点击或更多 - Javascript button toggle not working on first click, only second click or more ReactJS中的按钮第二次点击后才调用function,第一次点击后没有效果 - Button in ReactJS calls the function only after the second click, no effect after the first click 按钮在第一次点击时没有使用任何过滤器,第二次它正在工作 - button is not taking any filter in first click, in second it is working 切换 - Jquery 我想每当点击它显示的第一个按钮然后点击第二个按钮然后而不是第一个按钮的 div 标签隐藏 - toggle - Jquery I want to whenever click on first button it show and then click on second button then instead first button's div tag hide 点击按钮将第二次点击数据发送到 db 而不是第一个 php/ajax - click button sends second click data to db instead of the first one php/ajax 单击第一个操作,单击第二个按钮 - Button first action on click and second action on click 第二次单击按钮不起作用(JQuery) - Second click on button is not working (JQuery)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM