简体   繁体   中英

how to create smooth mouseover of an img in a div

I would like to make my img.icon_zoom (line 4) only appear with mouseover. This image would be the effect I want to gain. Therfore once the client hovers with the mouse the icon will fade in slowly. The picture behind is a link which will open a dropbox if clicked, its linked via class="piczoom". How should I do this?!?!

在此处输入图片说明

This is my actual code. Interesting part in first 4 lines:

<div id="tab1">
                    <div class="usual">
                        <a class="piczoom" href="_img/prensa/DOC2.jpg"><img alt="" src="./_img/prensa/photo_zoom.jpg"  class="photo_zoom" /></a>
                        <img class="icon_zoom" src="_img/prensa/icon.zoom.png" alt="zoom" />
                    </div>

                    <article>
                        <p class="p_title1"><img src="./_img/prensa/medio.png" alt="" /></p>
                        <img class="under1" src="./_img/prensa/underline.png" alt="" />
                        <p class="p_text">Revista la Moraleja</p>
                        <br>
                        <br>
                        <p class="p_title2"><img src="./_img/prensa/description.png" alt="" /></p>
                        <img class="under2" src="./_img/prensa/underline.png" alt="" />
                        <p class="desc_txt" class="p_text">Entrevista realizada por Antonio Corales. Visitaron el estudio mientras se realizaba los preparativos previos a la exposicion de Santander. Esta entrevista fue publicado en las tres primera paginas de la revista. hola
                        </p>
                        <br>
                        <div class="quote_box">
                            <img class="quote_left" src="./_img/prensa/quote.left.png" alt="" />
                            <p class="quote">Sus colores y textura te imnotizanaran</p>
                            <img class="quote_right" src="./_img/prensa/quote.right.png" alt="" />
                        </div>
                    </article>
                </div>

Its for a final school project so I appreciate it a lot!

since you want smooth, you probably want to preload your images, so add to your css...

div#preloaded-images {
    position: absolute;
    overflow: hidden;
    left: -9999px; 
    top: -9999px;
    height: 1px;
    width: 1px;
}

at the bottom of your html...

<div id="preloaded-images">
    <img src="path/to/my-image.png" width="1" height="1" alt="" />
</div>

Then add some jquery to fade your image in...

$('#mydiv').hover(function () {
    $('#imageId').fadeIn('slow', function() {});
}, 
function () {
    $('#imageId').fadeOut('slow', function() {});
});

At the end I found my answer with the answers I got. Thanks to all...

I created a code so once loaded the page the icon would fadeIn very slowly and after if the mouse hovers the hover fadeIn and FadeOut would get to work. Here is my code for any curious people, THANKS!!!!

<script type="text/javascript">
        /*JQ Fancybox for zoom foto*/
        $(document).ready(function() {
            $("a.piczoom").fancybox({
                'overlayShow'   : false,
                'transitionIn'  : 'elastic',
                'transitionOut' : 'elastic'
            });

            /*JQ to fade in on load*/
            $('.icon_zoom').hide().fadeIn(3000);

            /*JQ after load to work with hover*/
            $('.pic_zoom_box').hover(function () {
                $('.icon_zoom').fadeIn('slow', function() {});
            }, 
            function () {
                $('.icon_zoom').fadeOut('slow', function() {});
            });

        });
        </script>

<div class="pic_zoom_box" class="usual">
                            <a class="piczoom" href="_img/prensa/2_Cutted_zoom/diario_montanes/el_diario_Montanes.jpg">
                                <img alt="" src="_img/prensa/3_Cutted_preview/diario_montanes/el_diario_montanes.jpg"  class="photo_zoom" />
                                <img class="icon_zoom" src="_img/prensa/icon.zoom.png" alt="zoom" />
                            </a>
                        </div>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM