ボタンを押すと文章が表示され、再び押すと閉じるというものです。
Googleサイトで言うところの折りたたみ可能なグループと同等ですが、それをボタンで実現したものです。文字の大きさや色、行間、箇条書きスタイルの指定、プルダウン速度の指定、リンクを貼ることなど、自由に設定できます。使い方によってはおもしろいかと思います。
NO.2はボタンを画像に置き換えたものですが、Googleサイトでは普通に画像あるいは下記のように折りたたみ可能なグループからリンクを設定できますのであまり意味はないかもしれません。しかしサイト内の別ページにリンクする場合、コードによるものは別タブで、Googleの標準機能では同一タブで開きますので、使い分けても良いのかもしれません。
Googleサイト標準の「折りたたみ可能なグループ」を使った画像による展開(プルダウン)およびリンク
やり方の説明は、v をクリックして展開してください。
以下のコードは下にあります
NO.1
NO.2
画像クリックでメニュー開閉
NO.3
NO.4
NO.5
以下のコードを「埋め込む<>」➡「埋め込みコード」に貼り付け、挿入すればOKです。
他のサイトにリンクさせる場合はピンクの部分にリンク先のURLを貼り付けます。
Googleドライブのフォルダにアクセスする場合は、Googleドライブ内のフォルダを「右クリック➡共有➡リンクをコピー」で取得したURLをピンクの部分に(右クリック)で貼り付けてください。
紫の部分にはGoogleフォトで取得した画像のURLを貼り付けます。
文章のみを表示させたい場合には、<li><a href〜</a></li>の部分を削除し、赤の部分に文章を打ち込みます。
<li>〜</li>内の文章を改行する際は<br>をいれます。
なお、<li>〜</li>は何行あっても構いません。
青の箇所はお好きな名前に、オレンジの箇所でボタン幅の調整や文字色、その他の変更をしてください。
NO.1コード
<div class="btn-box">
<button>プルダウン ▽</button>
</div>
<div class="list">
<ul>
<li class="text">是非ごらんください</li>
<li><a href="https://sites.google.com/view/mininota/" >サイト mininota</a></li>
<li>ここに文章を打ち込んでください。</li>
<li class="text2">ここに文章を打ち込んでください。</li>
</ul>
</div>
<style>
.btn-box button {
width: 280px;
height: 50px;
padding: 8px;
font-size: 20px;
color: white;
background-color:royalblue;
border: none;
border-radius: 3px;
user-select: none;
cursor: pointer;
}
.btn-box button:hover {
opacity: 0.7; /* マウスオーバーした時のボタン色のぼかし具合 */
}
.list {
visibility: hidden;
opacity: 0;
transition: all 2.0s; /* プルダウンの速度 */
}
.list ul {
font-size: 16px; /* <li>〜</li>の文字サイズ */
margin: 18px 0px; /* ボタンと文章の距離 上、 左スペース */
line-height: 30px; /* 行間 */
padding: 0;
list-style: none; /* inside で箇条書きスタイルに */
}
.list.appear {
visibility: visible;
opacity: 1;
}
a {
color: blue; /* リンクの文字色 */
}
.text {
color: red; /* <li class="text">〜</li>内の文字色 */
font-size: 12px; /* 文字サイズ */
line-height: 25px; /* 行間 */
list-style: none;
}
.text2 {
color: orange; /* <li class="text2">〜</li>内の文字色 */
font-size: 16px; /* 文字サイズ */
line-height: 30px; /* 行間 */
list-style: inside;
}
</style>
<script>
const btn = document.querySelector('.btn-box button');
btn.addEventListener('click', () => {
const list = document.querySelector('.list');
list.classList.toggle('appear');
if (btn.textContent == "プルダウン ▽") {
btn.textContent = "△";
} else {
btn.textContent = "プルダウン ▽";
}
});
</script>
<li class="text">〜</li>と<li class="text2">〜</li>は、必要なければ削除してください
NO.2コード
<div class="btn-box">
<img src="https://lh3.googleusercontent.com/pw/AP1GczOxeQVDhTY2Kf9xnbGF_ztEZEBb0L8iHPq4wJmWHrwzQNyaLyN9vxnEsfQTll-fmWTHuAfcrNZGYYdI-ltX1nqcvyv_KBiGlQ-ssTYRvhHJRTdW97q2i1SF7a3gXgM9lTCSmVAluPA_Sx96GCo1XhR_LA=w300-h90-s-no-gm?authuser=0">
</div>
<div class="list">
<ul>
<li class="text2">下記アイコンクリックでリンクします</li>
<li class="text">Googleサイト 活用法</li>
<li><a href="https://sites.google.com/view/mininota/" ><img src="https://lh3.googleusercontent.com/pw/AP1GczNyz1Uq6c0SrFpog7kXujH6AqnBUzFfdGAmrl9KLicE1wWO5C4nSkukrG2OPLVJMdvxdDipPotPOaFRz6JwCes0j2dxfe8Lfe2UOKrxk7r-YJ4aYjuCrrbmtbReeuNvZeOu5nQdMfm6eP8orGPBR-kGrw=w250-h56-s-no-gm?authuser=0" width="180px" height="40px"></a></li>
</ul>
</div>
<style>
div {
cursor : pointer;
}
.list {
visibility: hidden;
opacity: 0;
transition: all 2.0s; /* プルダウンの速度 */
}
.list ul {
font-size: 16px; /* <li>〜</li>の文字サイズ */
margin: 18px 0px; /* ボタンと文章の距離 上、 左スペース */
line-height: 30px; /* 行間 */
padding: 0px;
list-style: none; /* inside で箇条書きスタイルに */
}
.list.appear {
visibility: visible;
opacity: 1;
}
a {
color: blue; /* リンクの文字色 */
}
.text {
color: red; /* <li class="text">〜</li>内の文字色 */
font-size: 12px; /* 文字サイズ */
line-height: 25px; /* 行間 */
list-style: none;
}
.text2 {
color: black; /* <li class="text2">〜</li>内の文字色 */
font-size: 16px; /* 文字サイズ */
line-height: 30px; /* 行間 */
list-style: none;
}
</style>
<script>
const btn = document.querySelector('.btn-box img');
btn.addEventListener('click', () => {
const list = document.querySelector('.list');
list.classList.toggle('appear');
});
</script>
画像はGoogleフォトにアップロードしたものを使用しています
NO.3コード
<div class="btn-box">
<button>わたしの好きな詩</button>
</div>
<textarea readonly class="list">
風景
純銀もざいく
山村暮鳥
いちめんのなのはな
いちめんのなのはな
いちめんのなのはな
いちめんのなのはな
いちめんのなのはな
いちめんのなのはな
いちめんのなのはな
かすかなるむぎぶえ
いちめんのなのはな
いちめんのなのはな
いちめんのなのはな
いちめんのなのはな
いちめんのなのはな
いちめんのなのはな
いちめんのなのはな
いちめんのなのはな
ひばりのおしやべり
いちめんのなのはな
いちめんのなのはな
いちめんのなのはな
いちめんのなのはな
いちめんのなのはな
いちめんのなのはな
いちめんのなのはな
いちめんのなのはな
やめるはひるのつき
いちめんのなのはな
</textarea>
<style>
.btn-box button {
width: 97vw;
height: 25vh;
padding: 8px;
font-size: 5vw;
color: white;
background-color: #3686c3;
border: none;
border-radius: 0px;
user-select: none;
cursor: pointer;
}
.btn-box button:hover {
opacity: 0.7; /* マウスオーバーした時のボタン色のぼかし具合 */
}
.list {
visibility: hidden;
opacity: 0;
transition: all 2.5s; /* プルダウンの速度 */
}
.list.appear {
visibility: visible;
opacity: 1;
}
.list {
color: #ffec47; /* 文字色 */
font-size: 2.0vw; /* 文字サイズ */
line-height: 2.75vw; /* 行間 */
list-style: none;
background-color: #075801;
padding-right: 3%;
padding-left: 0%;
padding-top: 14%;
padding-bottom: 0%;
writing-mode: vertical-rl; /* vertical-lr(縦書き左から右) horizontal-tb(横書き) sideways-rl sideways-lr */
width: 97vw;
height: 49.4vh;
}
</style>
<script>
const btn = document.querySelector('.btn-box button');
btn.addEventListener('click', () => {
const list = document.querySelector('.list');
list.classList.toggle('appear');
if (btn.textContent == "わたしの好きな詩") {
btn.textContent = "青空のもと 一面の菜の花(閉じる)";
} else {
btn.textContent = "わたしの好きな詩";
}
});
</script>
手動でコピーしてください
NO.4コード
<div class="btn-box">
<button>青空のもと いちめんのなのはな</button>
</div>
<div class="list">
<img src="https://lh3.googleusercontent.com/pw/AP1GczN6YXdv01_aCKs7O4ij96eSu20sDYHDlFVfYsFGxZ-saP9OpYw6D9gatM5OduVeFKgQL8q6rospLliAzSjtTuPL1czivnmQybySyfRT7hByLXoAtESZWtbkF1hlT5JmenOcE2RLQjqFPcavHAGRIqbBwQ=w766-h347-s-no-gm?authuser=0"></td>
</div>
<style>
img {
width: 100%;
height: auto;
}
.btn-box button {
width: 100%;
height: 25vh;
padding: 8px;
font-size: 5vw;
color: white;
background-color: #1690db;
border: none;
border-radius: 0px;
user-select: none;
cursor: pointer;
}
.btn-box button:hover {
opacity: 0.7; /* マウスオーバーした時のボタン色のぼかし具合 */
}
.list {
visibility: hidden;
opacity: 0;
transition: all 2.0s; /* プルダウンの速度 */
}
.list.appear {
visibility: visible;
opacity: 1;
}
</style>
<script>
const btn = document.querySelector('.btn-box button');
btn.addEventListener('click', () => {
const list = document.querySelector('.list');
list.classList.toggle('appear');
if (btn.textContent == "閉じる") {
btn.textContent = "青空のもと いちめんのなのはな";
} else {
btn.textContent = "閉じる";
}
});
</script>
NO.5コード
<div class="btn-box">
<button>複数画像(タイトル入り)▽</button>
</div>
<div class="list">
<table>
<!-- タイトル部分 不要なら<tr>〜</tr>を削除-->
<tr class="text">
<td>duckling</td>
<td>bird</td>
<td>puppy and kitten</td>
<td>puppy</td>
</tr>
<!-- 画像はそのまま貼り付けています -->
<tr>
<td><img src="https://lh3.googleusercontent.com/pw/AP1GczNi5xysTBcgaWQf3CdDYum7SK9Y9O84A8bBp_dHXj_ZW9Eu5QTbzWrj_6L_MQ5uyS81iMNkbbVdfu-SD6ECTNULv4aXr2pd9KFBn4-wr3nVwqhlwX14HuVLjOTA2K0pWFXc4X1xwTxwSQOkn7aay70Jcw=w650-h441-s-no-gm?authuser=0"></td>
<td><img src="https://lh3.googleusercontent.com/pw/AP1GczOn4RIyiyUAgejq3R7-eVtp_VjpQxyO7NFjQDCuhRSL-Cd4-DdKBHs19eNzf5L6LW_pV8rGKbYFE076_YzD_EWujZWuGTEOAkPnQyMHcjZ-mn2kgalylPFKniHYCofzgrNYNV0A11SFPDou50D5rl9KCg=w600-h375-s-no-gm?authuser=0"></td>
<td><img src="https://lh3.googleusercontent.com/pw/AP1GczOlAm_Ez7hLuGtRtm-QYoWDMZ8QdEV5vbYy4N3OtWBfOVJ2bfEm0xE5SZL5IL9hAClJchJKOt7eEANyhUq9v-5laGaqaxIpDkT_KxJjW65Q82nclcrY2H7BQP2w83RCihIzDZ5qpO8Dh6xVsOGnVDh4RA=w600-h375-s-no-gm?authuser=0"></td>
<td><img src="https://lh3.googleusercontent.com/pw/AP1GczPXn-cRU1GqimlKazsltWPHuS9vrL5Y_-Q0UaVm9PuLYWryjF5Tze0X0BVJJNFrM6bWZYtA9LOuE5jfCRyTdu9xtHjZmB5xVciB5MU5nDkrT2IX3dDyrWi87zPouKCADBtdprFitpJOnnm0D7N7dS-sDg=w600-h375-s-no-gm?authuser=0"></td>
</tr>
<!-- タイトル部分 -->
<tr class="text">
<td>piglet</td>
<td>hedgehog</td>
<td>kitten</td>
<td>rabbits</td>
</tr>
<tr>
<td><img src="https://lh3.googleusercontent.com/pw/AP1GczMeM8NoWCwKDdYofIO646jBa8upNacwyJuI2KjFe5j9rUaN9Us231PxcvktqXfS8BUJDoRwj-LG04XdhVpRUHtaaqakquCEYK2tg7B7cE8bT7n4QnoHjw8InaGFGPWuk7JcNu_zIykektxrG8ie8zYtlg=w600-h375-s-no-gm?authuser=0"></td>
<td><img src="https://lh3.googleusercontent.com/pw/AP1GczNcaauqfp-7BN3I-ufQgflBEHvotk9mMzMR8zNVDHoX6XD2oMgwWNLImxnJKm42GHbIsCi1RKWpyJKPCmH5-jXmBDbHnihQPj6_1wbbaNZxYYjTLVFH0LyN9JTf9Vko121Xo7kLwtHjfrYepz-tCHUpGg=w600-h375-s-no-gm?authuser=0"></td>
<td><img src="https://lh3.googleusercontent.com/pw/AP1GczNL6a_rYKaG3ZVl6akrxCdKswEj_HIeoO85dM5aDCpOFks7ZbfwUa6XyNt6K_lrPL8EajCurx5gQXue2zWycGOt_oBAAsNzMUuWKsVFocXtj3Tvh33ArlCe8dIrnQDmDQtsRp2TQLJ0GXzLoUhprVV19w=w600-h375-s-no-gm?authuser=0"></td>
<td><img src="https://lh3.googleusercontent.com/pw/AP1GczNjzAKQj7K6TjQLcpqx-xLNkqVaCrLvq1xU3Dvkj3Ftu-DvEGosW0mYor6X6mI0sM6qH63cAoX3rCXEB1CEDoEM5kArqYpHtFo1K18nBW3gerVqS91oL7sRydgjLx5vt9rNUmOuiJW17vyUlRCsl6hcjw=w600-h375-s-no-gm?authuser=0"></td>
</tr>
</table>
</div>
<style>
table {
border-spacing: 10px 10px; /* テーブルの上下・左右間隔 */
}
img {
width: 100%;
height: auto;
}
.btn-box button {
width: 240px;
height: 40px;
padding: 0px;
font-size: 16px;
color: white;
background-color: #C12872;
border: none;
border-radius: 3px;
user-select: none;
cursor: pointer;
margin-bottom: 10px;
}
.btn-box button:hover {
opacity: 0.7; /* マウスオーバーした時のボタン色のぼかし具合 */
}
.list {
visibility: hidden;
opacity: 0;
transition: all 2.0s; /* プルダウンの速度 */
}
.list.appear {
visibility: visible;
opacity: 1;
}
.text {
font-size: 1.8vw;
line-height: 10px;
color: blue;
}
</style>
<script>
const btn = document.querySelector('.btn-box button');
btn.addEventListener('click', () => {
const list = document.querySelector('.list');
list.classList.toggle('appear');
if (btn.textContent == "閉じる") {
btn.textContent = "複数画像(タイトル入り)▽";
} else {
btn.textContent = "閉じる";
}
});
</script>