【问题标题】:jquery image rollover behaviourjquery 图像翻转行为
【发布时间】:2012-05-29 00:08:56
【问题描述】:

我有以下代码允许缩略图 src attr 替换主图像窗口中的图像。

        $(document).ready(function(){   
            var originalimg = $('#imageMain img').attr('src');
                $(".subImage").hover(function(){
                        var currentimg = $(this).attr('src');
                    $('.mainImage').fadeOut(function () {
                    $('.mainImage').attr('src', currentimg).fadeIn();
                        });
                    },function(){
                            $('.mainImage').fadeOut(function() {
                                $('.mainImage').attr('src', originalimg).fadeIn();
                            })
                            });
            });

目前该行为执行以下操作: 1. 悬停 - 主图像淡入白色,然后淡入子图像。 2. 鼠标移出 - 主图像淡化为白色,然后替换为原始图像。

我真正需要的不是两个图像状态之间的“白色”过渡,我希望它们有点重叠(所以一个淡出,另一个淡入) -

这可能吗?

谢谢

【问题讨论】:

    标签: jquery image thumbnails behavior


    【解决方案1】:

    您不能使用淡出/淡入顺序旋转图像。您必须以另一种方式进行转换。我已经为您编写了整个代码:

        <head>
        <title>jQuery Image Rotator</title>
       <script type="text/javascript" src="jquery-1.3.2.js"></script>
        <script type="text/javascript">
          $("#photoshow").hover(function() {
            setInterval("rotateImages()", 2000); // set the interval time as your wish
        });
    
        function rotateImages() {
            var oCurPhoto = $('#photoShow div.current');
            var oNxtPhoto = oCurPhoto.next();
            if (oNxtPhoto.length == 0)
                oNxtPhoto = $('#photoShow div:first');
    
            oCurPhoto.removeClass('current').addClass('previous');
            oNxtPhoto.css({ opacity: 0.0 }).addClass('current').animate({ opacity: 1.0 }, 1000,
                function() {
                    oCurPhoto.removeClass('previous');
                });
        }
    </script>
           <style type="text/css">
             #photoShow {
            height:400px;
             width:400px;
             }
          #photoShow div {
            position:absolute;
            z-index: 0;
             }
          #photoShow div.previous {
            z-index: 1;
             }
             #photoShow div.current {
              z-index: 2;
               }
    </style>
        </head>
      <body>
        <div id="photoShow">
           <div class="current">
            <img src="images/Grass.jpg" alt="Photo Gallery" width="400" height="400" class="gallery" />
        </div>
        <div>
            <img src="images/Leaf.jpg" alt="Photo Gallery" width="400" height="400" class="gallery" />
        </div>
        <div>
            <img src="images/Spring.jpg" alt="Photo Gallery" width="400" height="400" class="gallery" />
        </div>
        <div>
            <img src="images/Water.jpg" alt="Photo Gallery" width="400" height="400" class="gallery" />
        </div>
         </div>
       </body>
        </html>
    

    它将一张一张地转换图像。替换为适当的类、id 名称和图像 url。希望它有帮助!

    【讨论】:

    • 谢谢,我有点明白这是什么意思,但我无法让 ti 工作。它只显示grass.jpg。
    猜你喜欢
    • 1970-01-01
    • 2011-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-13
    • 2014-09-27
    相关资源
    最近更新 更多