-2

で画像を別の画像に置き換えたいのhoverですが、実装に苦労しています。ホバーしても何も起こらないようです。

JSフィドル

<div id="container">
    <div class="content">
        <div class="left">
            <a href="#"><img src="http://dummyimage.com/307x349/000/fff" alt="tyler st salon home"></a>
        </div><!-- end left -->
        <div class="center">
            <a href="#" class="top"><img src="http://dummyimage.com/307x166/000/fff" alt="about tyler st salon" class="about_hover"></a>
            <a href="#" class="bottom"><img src="http://dummyimage.com/307x166/000/fff" alt="tyler st salon service" class="services_hover"></a>
        </div><!-- end center -->
        <div class="right">
            <a href="#" class="top"><img src="http://dummyimage.com/307x166/000/fff" alt="tyler st salon products" class="products_hover"></a>
            <a href="#" class="bottom"><img src="http://dummyimage.com/307x166/000/fff" alt="contact tyler st salon" class="contact_hover"></a>
        </div><!-- end right -->
    </div><!-- end content -->    

</div><!-- end container -->

html, body, #container, .content, .left, .right, .center {
    height: 100%;
}

#container {
    min-height: 349px;
}

#container {
    margin: 0 auto;
    width: 960px;
}

#container .content {
    margin-top: 115px;
    position: relative;
}

#container .content .left,
#container .content .center,
#container .content .right { 
    position: relative;
    width: 307px;
}

#container .content .left {
    float: left;
}

#container .content .center {
    float: left;
    padding-left: 19px;
}

#container .content .right {
    float: right;
}

#container .content .top,
#container .content .bottom {
    position: absolute;
}

#container .content .top {
    top: 0;
}

#container .content .bottom {
    bottom: 0;
}

#container .content .center .about_hover {
    width: 307px;
    height: 166px;
    background: url('img/about_hover.jpg') center center no-repeat;
}

#container .content .center .services_hover {
    width: 307px;
    height: 166px;
    background: url('img/services_hover.jpg') center center no-repeat;
}

#container .content .center .products_hover {
    width: 307px;
    height: 166px;
    background: url('img/products_hover.jpg') center center no-repeat;
}

#container .content .center .contact_hover {
    width: 307px;
    height: 166px;
    background: url('img/contact_hover.jpg') center center no-repeat;
}
4

4 に答える 4

2

ここに1つのバリアントがありますこのフィドル
をチェックし てくださいホバーすると画像が非表示になります

a:hover img
{
    display:none;
}

<a>背景画像をタグに設定します(クラスを画像から移動しました) 。

<a href="#" class="top about_hover">

サンプルフィドルはあなたのために適用されます<a class="top"...

自由に遊んでください

于 2013-04-12T22:20:56.557 に答える
1

CSS は、画像で覆われている領域の背景の変更を指定します。実際に画像を変更するには<img src="...">、おそらく javascript のホバー イベント (または mousein/mouseout) リスナーを介して、コンテンツを変更する必要があります。

この回答は、クリックイベントで画像を変更する方法を示しています。ホバー イベントに適応するには、イベント リスナーを次のように変更します。.hover()

于 2013-04-12T22:15:45.807 に答える
0

これはJavaScriptの画像交換の例です(jQueryなし)

<!doctype html>
<html>
<head>
<script>
function byId(e){return document.getElementById(e);}
window.addEventListener('load', myInit, false);

function myInit()
{
    byId('img1').addEventListener('mouseover', onMouseOverOut, false);
    byId('img1').addEventListener('mouseout', onMouseOverOut, false);
}

// swaps the hoverImg and src attributes of the image it's attached to as an event handler
function onMouseOverOut()
{
    var tmp = this.src;
    this.src = this.getAttribute('hoverImg');
    this.setAttribute('hoverImg', tmp);
}
</script>
<style>
#img1
{
    height: 256px;
    width: 256px;
}
</style>
</head>
<body>
    <img id='img1' hoverImg='http://www.gravatar.com/avatar/c89d764421e3857bf346733ff58d8d2a?s=128&d=identicon&r=PG' src='http://dummyimage.com/307x349/000/fff'/>
</body>
</html>
于 2013-04-12T22:29:48.997 に答える
0

これは正しい書き方です:

.element:hover{
/* stuff */
}

これは間違っています:

.element_hover{
    /* stuff */
    }
于 2013-04-12T22:17:59.353 に答える