2016-05-10 5 views
6

私はかなりのバグの多い広告のツールヒントに取り組んできました。明らかに、それらはタッチインタフェースでは動作しません。私のツールチップをタッチスクリーンに適合させることはできますか?

私は理想的に純粋なHTML5とCSS3に限られています。間違いなく、jqueryは理想的にはjavascriptではありません。私は(またはむしろ)追加:変更を試みた:アクティブな:ホバークラスが何もタッチスクリーン上でまったく起こりません。

現在のHTMLとCSSは(と私はリンクヘルプアニメーションを含めていないが、あなたのアイデアを得る)CSSで起こっているいくつかのアニメーションと策略

.tiptext { 
 
    cursor: help; 
 
    color: black; 
 
    font-family: 'ProximaNova', 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; 
 
    font-weight: 600 !important; 
 
    border-bottom: 1px solid #ebebeb; 
 
    box-shadow: inset 0 -5px 0 #ebebeb; 
 
    -webkit-transition: background .15s cubic-bezier(.33, .66, .66, 1); 
 
    transition: background .15s cubic-bezier(.33, .66, .66, 1); 
 
    text-decoration: none; 
 
    font-size: 14px; 
 
    line-height: 172%; 
 
    -webkit-animation-name: link-helpoff; 
 
    -webkit-animation-duration: 1s; 
 
    animation-name: link-helpoff; 
 
    animation-duration: 1s; 
 
    -webkit-animation-fill-mode: both; 
 
    animation-fill-mode: both; 
 
    transition-delay: 0.4s; 
 
} 
 
.tiptext::after { 
 
    content: ""; 
 
    position: fixed; 
 
    top: 0; 
 
    left: 0; 
 
    right: 0; 
 
    bottom: 0; 
 
    pointer-events: none; 
 
    color: transparent; 
 
    background-color: transparent; 
 
    transition: background-color 0.5s linear; 
 
} 
 
.tiptext:hover::after { 
 
    background-color: rgba(255, 255, 255, 0.6); 
 
} 
 
.description { 
 
    border: 1px solid #e3e3e3; 
 
    background: white; 
 
    width: auto; 
 
    max-width: 275px; 
 
    height: auto; 
 
    padding: 10px; 
 
    font-family: 'ProximaNova', 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; 
 
    font-weight: 300; 
 
    color: rgb(39, 44, 45); 
 
    font-size: 13px; 
 
    z-index: 500; 
 
    position: absolute; 
 
    margin-left: 50px; 
 
    margin-top: 20px; 
 
    cursor: default; 
 
    display: inline-block; 
 
} 
 
.tiptext > .description { 
 
    visibility: hidden; 
 
    opacity: 0; 
 
    transition: visibility 0s linear 0.4s, opacity 0.4s linear; 
 
} 
 
.tiptext:hover > .description { 
 
    visibility: visible; 
 
    opacity: 1; 
 
    transition-delay: 0s; 
 
    -webkit-transition: opacity 0.2s ease-in; 
 
    -moz-transition: opacity 0.2s ease-in; 
 
    -ms-transition: opacity 0.2s ease-in; 
 
    -o-transition: opacity 0.2s ease-in; 
 
    transition: opacity 0.2s ease-in; 
 
} 
 
.tiptext:hover { 
 
    color: black; 
 
    -webkit-animation-name: link-help; 
 
    -webkit-animation-duration: 0.6s; 
 
    animation-name: link-help; 
 
    animation-duration: 0.6s; 
 
    -webkit-animation-fill-mode: both; 
 
    animation-fill-mode: both; 
 
    transition-delay: 0s; 
 
}
<span class="tiptext"> 
 
    <span class="description" style="text-align:center;">You can read more about the topic in this pop up box</span> 
 
    Mouse over me to learn more. 
 
</span>

あり基本的にボックスはマウスの上にマウスを置くとフェードイン、フェードアウトします。また、フルスクリーンの白い背景があり、少し不透明でフェードインして、マウスオーバーしたボックスをフォーカスします。スクリーンデバイス。

タッチスクリーンデバイスのプレスで同じポップアップボックスを表示するには、大幅な変更が必要な場合があります。

+0

私は気にしないだろうが、私は何も(への変更:アクティブ、:DIVにフォーカス、変更スパンは)でも、ツールチップが私のいずれかで表示させることはできませんiOSデバイスでは、何もしません。 –

答えて

1

はい、方法があります。

最初に、ボタンに属性「ontouchstart」を追加します。 2番目:アクティブ、:フォーカス、および:ホバーのスタイルを追加します。

これをiOSでテストしたところ、動作しています。 (Androidで試したことはありません)。それを行うには

div { 
 
    display: none; 
 
} 
 
button { 
 
    width: 200px; 
 
    height: 50px; 
 
    border: 1px solid red; 
 
    display: inline-block; 
 
    
 
} 
 
button:active, 
 
button:focus, 
 
button: hover { 
 
    background-color: blue; 
 
} 
 
button:active + div, 
 
button:focus + div, 
 
button:hover + div { 
 
    display: block; 
 
}
<p>Hello</p> 
 
<button ontouchstart>Activate</button> 
 
<div>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Impedit, ipsa, officiis! Est voluptatibus explicabo sed atque provident vel deleniti nulla quis, ipsa quas dolorum, dolorem cum possimus accusamus impedit nostrum!</div> 
 
<p>Goodbye</p>

+0

Androidでも動作します! – JakobMillah

+0

こんにちは@halterswebだけで私のコードにそれを翻訳しようとしている - 私はボタンを持っていないとして、代わりに浮動ツールチップがあります - 私のレコードでは、 "ボタン"は私のツールチップのタイトルになるでしょうか?スパンに 'ontouchstart'を追加できますか? –

+0

これを実装するためのオリジナルのコードを書き直しましたが、私が苦労しているモバイルデバイスのツールチップのスタイリングとは別です([リンク](http://stackoverflow.com/questions/37159636/)を参照)。私が持っている唯一の問題は、デスクトップ上で、あなたはツールチップボックス内のデスクを強調表示するか、その上にマウスを置くことができるということですマウスを離すとすぐに消えるので、リンクをクリックしてボックスの上にマウスを置くとアクティブに保たれます。有効にするには微調整が必​​要ですか? –

1

一つの方法は、それを-1の値を与え、あなたの.tiptext要素にtabindex属性を追加することです。これにより、要素がフォーカスを受け取ることができるため、擬似クラス:focusで選択できます。

また:active:focus擬似クラスを認識するためのiOSを得るためにあなたのbodyタグ(またはあなたが作業している要素のいずれかの親要素)にtouchstartイベントを追加する必要があります。

<body ontouchstart> 

.tiptext { 
 
    cursor: help; 
 
    color: black; 
 
    font-family: 'ProximaNova', 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; 
 
    font-weight: 600 !important; 
 
    border-bottom: 1px solid #ebebeb; 
 
    box-shadow: inset 0 -5px 0 #ebebeb; 
 
    -webkit-transition: background .15s cubic-bezier(.33, .66, .66, 1); 
 
    transition: background .15s cubic-bezier(.33, .66, .66, 1); 
 
    text-decoration: none; 
 
    font-size: 14px; 
 
    line-height: 172%; 
 
    -webkit-animation-name: link-helpoff; 
 
    -webkit-animation-duration: 1s; 
 
    animation-name: link-helpoff; 
 
    animation-duration: 1s; 
 
    -webkit-animation-fill-mode: both; 
 
    animation-fill-mode: both; 
 
    transition-delay: 0.4s; 
 
} 
 
.tiptext::after { 
 
    content: ""; 
 
    position: fixed; 
 
    top: 0; 
 
    left: 0; 
 
    right: 0; 
 
    bottom: 0; 
 
    pointer-events: none; 
 
    color: transparent; 
 
    background-color: transparent; 
 
    transition: background-color 0.5s linear; 
 
} 
 
.tiptext:focus::after,.tiptext:hover::after { 
 
    background-color: rgba(255, 255, 255, 0.6); 
 
} 
 
.description { 
 
    border: 1px solid #e3e3e3; 
 
    background: white; 
 
    width: auto; 
 
    max-width: 275px; 
 
    height: auto; 
 
    padding: 10px; 
 
    font-family: 'ProximaNova', 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; 
 
    font-weight: 300; 
 
    color: rgb(39, 44, 45); 
 
    font-size: 13px; 
 
    z-index: 500; 
 
    position: absolute; 
 
    margin-left: 50px; 
 
    margin-top: 20px; 
 
    cursor: default; 
 
    display: inline-block; 
 
} 
 
.tiptext > .description { 
 
    visibility: hidden; 
 
    opacity: 0; 
 
    transition: visibility 0s linear 0.4s, opacity 0.4s linear; 
 
} 
 
.tiptext:focus > .description,.tiptext:hover > .description { 
 
    visibility: visible; 
 
    opacity: 1; 
 
    transition-delay: 0s; 
 
    -webkit-transition: opacity 0.2s ease-in; 
 
    -moz-transition: opacity 0.2s ease-in; 
 
    -ms-transition: opacity 0.2s ease-in; 
 
    -o-transition: opacity 0.2s ease-in; 
 
    transition: opacity 0.2s ease-in; 
 
} 
 
.tiptext:focus,.tiptext:hover { 
 
    color: black; 
 
    -webkit-animation-name: link-help; 
 
    -webkit-animation-duration: 0.6s; 
 
    animation-name: link-help; 
 
    animation-duration: 0.6s; 
 
    -webkit-animation-fill-mode: both; 
 
    animation-fill-mode: both; 
 
    transition-delay: 0s; 
 
}
<span class="tiptext" tabindex="-1"> 
 
    <span class="description" style="text-align:center;">You can read more about the topic in this pop up box</span> 
 
    Mouse over me to learn more. 
 
</span>

+0

これはそれにクラックがあるかもしれないと思っていましたが、iOSではそれを押しても何もしません。私は元のコードとレイアウトがこれを動作させるために動く必要があると思います。あるいは、モバイルデバイス上で何かをするために空の 'href'を持っている必要があります。 –

+0

'tabindex'を' 0'に設定するか、 ':focus'の代わりに':active'疑似クラスを使って動作するかどうか試してみてください。ただし、 'tabindex'を' 0'に設定すると、 '.tiptext'要素はTabキーでページを走査するときに最初にフォーカスされるようになります。 – Shaggy

+0

@halterswebから "ontouchstart"を追加することは、そのトリックをやったようです - ちょうどモバイルのためにこれらのボックスをスタイリングするだけです。 –

関連する問題