トップに戻るのボタンを設置しましたが、スマホだと表示されません。
PCでもウインドウの幅を狭めると消えますので、ウインドウサイズに対して何か指定がいるのかもしれませんが、そのへんの設定がよくわかりません。
CSSとHTMLは下記です。
わかる方ご教授ください。
CSS
#page_top{
width: 100px;
height: 100px;
position: fixed;
right: 100px;
bottom: 100px;
background: #DE2C58;
opacity: 0.6;
border-radius: 50%;
}
#page_top a{
position: relative;
display: block;
width: 50px;
height: 50px;
text-decoration: none;
}
#page_top a::before{
font-family: FontAwesome;
content: '\f0d8';
font-size: 50px;
color: #fff;
position: absolute;
width: 100px;
height: 50px;
top: 60px;
bottom: 0;
right: 0;
left: 0;
margin: auto;
text-align: center;
}
HTML
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7 … rel="stylesheet" >
<div id="page_top"><a href="#"></a></div>
<script>
$(function() {
var pagetop = $('#page_top');
pagetop.hide();
$(window).scroll(function () {
if ($(this).scrollTop() > 100) { //100pxスクロールしたら表示
pagetop.fadeIn();
} else {
pagetop.fadeOut();
}
});
$('a[href^="#"]').click(function(){
var time = 500;
var href= $(this).attr("href");
var target = $(href == "#" ? 'html' : href);
var distance = target.offset().top;
$("html, body").animate({scrollTop:distance}, time, "swing");
return false;
});
});
</script>
お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!
関連するカテゴリからQ&Aを探す
おすすめ情報
- ・漫画をレンタルでお得に読める!
- ・人生のプチ美学を教えてください!!
- ・10秒目をつむったら…
- ・あなたの習慣について教えてください!!
- ・牛、豚、鶏、どれか一つ食べられなくなるとしたら?
- ・【大喜利】【投稿~9/18】 おとぎ話『桃太郎』の知られざるエピソード
- ・街中で見かけて「グッときた人」の思い出
- ・「一気に最後まで読んだ」本、教えて下さい!
- ・幼稚園時代「何組」でしたか?
- ・激凹みから立ち直る方法
- ・1つだけ過去を変えられるとしたら?
- ・【あるあるbot連動企画】あるあるbotに投稿したけど採用されなかったあるある募集
- ・【あるあるbot連動企画】フォロワー20万人のアカウントであなたのあるあるを披露してみませんか?
- ・映画のエンドロール観る派?観ない派?
- ・海外旅行から帰ってきたら、まず何を食べる?
- ・誕生日にもらった意外なもの
- ・天使と悪魔選手権
- ・ちょっと先の未来クイズ第2問
- ・【大喜利】【投稿~9/7】 ロボットの住む世界で流行ってる罰ゲームとは?
- ・推しミネラルウォーターはありますか?
- ・都道府県穴埋めゲーム
- ・この人頭いいなと思ったエピソード
- ・準・究極の選択
デイリーランキングこのカテゴリの人気デイリーQ&Aランキング
-
ウインドウを小さくするとbody...
-
htmlの文字が縦書きになる
-
CSSで背景画像を一番下にもって...
-
【HTML&CSS】フッター下部の余...
-
widthやheightの数値に単位(px...
-
CSSを使ってスクロールバーつき...
-
CSS backgroundが反映されない件
-
画像リンクの下に文字を付けた...
-
スクロールボックスを中央に配...
-
CSSでボックスのheightが0になる
-
CSSだけで、テーブルにスクロー...
-
heaerとfooterに背景画像が難し...
-
CSS:animation開始位置の設定
-
cssでの幅の分割(固定・可変混...
-
CSSでborderの指定を解除する記...
-
<li>の黒い点を消したい。
-
Win IE5.5~6.0での余白に関す...
-
HTMLで文字が重なって表示されます
-
divタグ+CSSでのレイアウトで、...
-
4枚の画像を均等間隔で一列に...
マンスリーランキングこのカテゴリの人気マンスリーQ&Aランキング
-
htmlの文字が縦書きになる
-
widthやheightの数値に単位(px...
-
css初心者 フレックスボックス...
-
CSSがなぜかfont-sizeだけ効か...
-
【CSS】ヘッダーの高さが不明の...
-
画像イメージの上下左右、欲し...
-
CSS、width100%でもできる余白
-
スクロールボックスを中央に配...
-
<div>と<div>の間の10px程の...
-
CSSで背景画像を一番下にもって...
-
余分な縦スクロールバーが出て...
-
CSS:animation開始位置の設定
-
form input テキストを上下中央...
-
Media Queries 4 で 非推奨とな...
-
CSSでボックスのheightが0になる
-
W3Cのソースコードの検証サービ...
-
表示倍率を変えるとレイアウト...
-
定義リストに下線をつけたいと...
-
背景が下まで表示されないんです。
-
footer を横幅いっぱいに広げる...
おすすめ情報