表示領域を取得するときにお馴染みの $(window).height(); をiPhoneのSafariで考えなしに使うと痛い目を見るのでメモとして残しておく。 環境 iPhone 5s(iOS8.1) jQuery 1.11.1 注意すべきところ iPhoneのSafariが他のブラウザと比べて特徴的なのがURLバー(を含む上下のバー)がスクロールで小さくなったりする部分。これが本当にやっかいな挙動をする。 縦(portrait)表示の時は良いとして、問題なのは横(landscape)表示のとき。 URLバー(を含む上下のバー)は、縦から横に回転させたとき隠れ、スクロールすると表示される。 このURLバー(を含む上下のバー)が表示されているか否かで、表示領域の高さは変わるはずなのに、$(window).height()は同じ値を返す。 iPhone 5sで実行した時返す値 取得方法 UR
// スクロールを無効にする $(window).on('touchmove.noScroll', function(e) { e.preventDefault(); }); // スクロール無効を解除する $(window).off('.noScroll'); スマホの独自イベントのtouchmoveイベントを切ってスクロールを止める。 解除したい時はoffする。 イベント名に、.noScrollと名前を付けることで、他の部分でtouchmoveイベントを使っていたとしても、そのtouchmoveイベントまでイベントをoff()してしまうこともなく、.noScrollの名前のイベントのみをoff()することができる。 参考 iphoneでスクロールをさせない処理をする。 特定のエリアのみスクロールを無効にする方法 ドロワーメニューを左側に表示するときにコンテンツ側を固定するときなど //
問題 リンク(a要素)のリンク先(href属性)の絶対パスを取得したい。 HTML中には相対パスで書いてあるんだけど。 答え ここにa要素を用意 → ソフテルのコーポレートサイトはこのブログ記事の上の上の上の階層です リンク先は「../../../index.php」。 DOM関数で document.getElementById("ID").href jqueryで $("#ID").prop('href') でも getAttributeを使うと? //hrefに書いた文字そのまま document.getElementById("#ID").getAttribute("href") //でも古いIEだけ違う動きをするかも
jQuery.ajax()について逆引きリファレンスっぽくまとめてみました。 まとめた理由は、ネットで「jQuery.ajax」や「jQuery.ajax サンプル」などで調べても、いい感じの内容がなかなかヒットしないことと、よくヒットするサイトの情報が古かったりする(1.4で止まっているとか)ためです。 ということで、2012年10月現在2014年10月現在の「jQuery.ajax()」などをざっと調べて作ってみました。 初心者向けの内容です。すべてのオプションは網羅できていません。とりあえずサンプルコードがほしい方は15項をご覧ください。 若番から必要と思われるものを順番に並べているつもりですが、後半は適当です。また、各項のサンプルはなんとなく積み上げていく感じにしています。 調べている間にも3つくらい新しい発見(といっても古い情報ですが…)があり、jQueryが日々進化していること
スマートフォン用のサイトを作る場合は、jQuery Mobileやら、jQTouchやら、Sencha Touchやら色々ありますが、ちょっとそこまで必要ないときに、スマートフォン特有のイベントをjQueryを使って扱えないか触ってみました。 スマホ特有のイベント スマホ特有のイベントは幾つかありますが、今回は特に使われるであろうタッチ、スライド、ピンチイン、ピンチアウトに重点を置いて調べてみました。 上記操作に必要なイベントは以下の通りです。 touchstart touchmove touchend touchcancel gesturestart gesturechange gestureend 「touch***」というイベントが画面に指でタッチした、している時のイベント、「gesture***」というイベントが「二本指以上」の操作(ピンチイン、ピンチアウト、回転等)を行っている時
iOS, Android端末の画面の向きにあわせてゴニョゴニョしてみたい。 縦(Portrait), 横(Landscape)になった時の画面幅を取得しようとしています。 本来であればイベント “onorientationchange” という便利なものがあるので使えばいいんだろうけど、一部Androidで取得できないケースもある様子、で困ったなぁと… 無駄を承知でこんな風にしてみました。 jQueryを使用しています。 $(window).on('resize orientationchange', function () { console.log(window.innerWidth); }); resizeだけでも良かったと思うのですが、HTML, CSSのどちらかが悪いのかiOSでresizeイベントをうまく取得できません。 仕方なくorientationchangeも監視対象にし
京アニ放火事件を受けて、メルカリに京アニ関連グッズ出品が急増しています。しかし中には高額すぎる出品があったり、そもそもメルカリで京アニグッズ …
Move Elements with Style Quickly convert simple, semantic HTML structures into a sexy interactive turntables! Roundabout is a jQuery plugin that converts a structure of static HTML elements into a highly customizable turntable-like interactive area. (And now, not just turntables, but many shapes!) In its simplest configuration, Roundabout works with ordered- and unordered-lists, however after som
What is Masonry? Masonry is a JavaScript grid layout library. It works by placing elements in optimal position based on available vertical space, sort of like a mason fitting stones in a wall. You’ve probably seen it in use all over the Internet. Install Download CDN Package managers Getting started HTML CSS Initialize with jQuery Initialize with Vanilla JavaScript Initialize in HTML Next MIT Lice
jQueryでスクロールすると表示する系いろいろ 最近はスクロールするときにいろいろ仕掛けをするのが流行なようです。 ここではシンプルにある要素の位置とか最下部までスクロールしたら何か表示するということをやってみます。 投稿日2012年03月08日 更新日2019年12月19日 ちょっとスクロールするとフェードして「トップへ戻るボタン」を表示を表示します。 ボタンは下の方にこんな感じで配置します。 html <p id="page-top"><a href="#wrap">PAGE TOP</a></p> fixedにすると固定配置されます。 css #page-top { position: fixed; bottom: 20px; right: 20px; font-size: 77%; } #page-top a { background: #666; text-decoration
こなだいスライドショーをjQueryを利用して作ったんですが、IEだと画像の読み込みがどうも遅い。たぶん事前にキャッシュさせなきゃいけないんだろうなぁと思いつつも方法がわからず、先に読み込んでCSSで消すって方法を採用しました。 でもこれだとどうもスマートじゃない。何か方法があるでしょ、と思っていたらやっぱりありました。 こういうコードをDOM readyイベントの外に書いておくといいみたいです。 var images = ["hoge1.jpg", "hoge2.jpg", "hoge3.jpg"]; $.each(images, function(){ $("<img>").attr("src", this); }); こんな簡単だなんて・・・。jQueryはやっぱり凄いです。
jQueryプラグインの習作をするために作成したモノではありますが、プラグイン化したことでかなり楽に使えるようになったので、気が向いたら使ってみてください。 ライブラリについて HTMLを汚さず、簡単に画像のロールオーバーを実装できます。 ダウンロード jquery.rollover.js - v1.0.4 ライセンス MIT License 主な機能 HTMLで指定するのは初期表示の画像だけ 指定された箇所でも _on が付いている画像は無視 ロールオーバー画像をプリロード 拡張子は何でもOK (png, jpg, jpeg, gif, etc…) ロールオーバー画像を示す _on の部分を自由に変更できる 使用方法 画像を用意する example.jpg をロールオーバーしたい場合は、名前の末尾に _on を付けた画像 example_on.jpg を example.jpg と同じデ
案件でオリジナルなスクロールバーを設置する必要があり、色々と調べてみるとjScrollPaneが便利そうです。実装のやり方をググってみたところ、サンプルはあるもののなかなか設置の仕方まで解説しているところはありませんでした。しょうがないので自分でまとめてみることにしました。パンが無いならケーキを食べればいいじゃない的なノリで。違うか。 以下が公式サイトです。 http://www.kelvinluck.com/assets/jquery/jScrollPane/jScrollPane.html 最低限+一般的に必要なファイルは以下の通りです。 * jQuery * the mouse wheel plugin * the jQEm plugin * jScrollPane.js * jScrollPane.css これらをダウンロードし、任意のフォルダに配置します。 ※
フォームを作る際に、ユーザビリティを激的に向上させるひとつに、チェックボックスやラジオボタンと一緒に使うlabelタグがあります。 例えば↓これが普通のチェックボックス チェックして下さい これにlabelタグをつけてあげると↓こんな感じ チェックして下さい こうすると、「チェックして下さい」をクリックしても、チェックボックスにチェックが入ります。 ただ、iPhoneやiPadに搭載されているブラウザのMobile Safariでは、このラベルタグが使えません。。 使えるようにして欲しいですがしょうがないです。 なのでJavaScriptで解決! 手っ取り早くjQueryでliにclickイベントを発動させてあげるだけ! jQueryを読み込んでいる前提で、下記の感じで <!-- ↓html↓--> <ul> <li><input name="test" value="test" type
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く