0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

jQueryで上からslideToggleでメッセージを出す

Last updated at Posted at 2021-03-02

##はじめに
slideToggleを使ってニュルっとメッセージを出す方法の記録です。

##jQueryのコード
以下のコードでメッセージの出す、戻すを行う。
表示するメッセージを受け取った場合は空白を全て取り除く。
そしてslideToggleで表示し、5秒後にslideToggleで戻す。

let $slideMsg = $('#js-slide-msg');
let msg = $slideMsg.text();
  if(msg.replace(/\s+/g, "")){
   $slideMsg.slideToggle().show();
   setTimeout(function(){
    $slideMsg.slideToggle().show();
   }, 5000);
  }

##表示について
$msgに表示するメッセージが入っていれば表示させる。

<div id="js-slide-msg">
    <?php if(!empty($msg) echo $msg; ?>
</div>
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?