LoginSignup
2
1

More than 5 years have passed since last update.

ブックマークレット用 Toastもどき。

Last updated at Posted at 2018-06-03

まぁ、タイトル通りです。

基本的に これ単体で使うことは想定していません。

ブックマークレットの中で、alert を使うと「閉じるのが面倒くさい」且つ「何も表示しないのは心許ない」という時に使ってます。

javascript:void(function(){

var sc = document.scrollingElement.scrollTop; 

var text = document.createElement('span');
text.innerHTML='色は匂へど 散りぬるを<br><b>我が世誰そ 常ならむ</b><br><font color=red>有為の奥山 今日越えて</font><br>浅き夢見じ 酔ひもせず';

var ts = text.style;

ts.color = '#000';
ts.backgroundColor = 'white';
ts.padding = '15px';
ts.border = '1px solid gainsboro';
ts.boxShadow = '3px 3px 10px';
ts.zIndex = '100';

document.body.appendChild(text);

ts.position = 'absolute'; 
ts.top = 50 + sc + 'px'; 
ts.left = (window.innerWidth / 2)-(text.offsetWidth / 2) + 'px'; 

setTimeout(function () { text.style.visibility = "hidden"; }, 1500);

}())

ちなみに、removeChild せずに、CSSで非表示にしているだけなので、ゴミは残ります。

動作確認環境

Windows 10
Google Chrome 67

2
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
2
1