打开扩展/关闭以恢复原始大小,一系列带有img淡入淡出的框 [英] open expand/ close back to original sizes a series of boxes with img fade

查看:97
本文介绍了打开扩展/关闭以恢复原始大小,一系列带有img淡入淡出的框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一系列可点击的框.我需要能够展开框并隐藏其img.我还需要能够关闭以前打开的文件,使其恢复到其原始高度和定义的宽度,同时使其img退回. .info加载ajax内容

I have a series of clickable boxes. I need to be able to expand the boxes and hide its img. I also need to be able to close previous opened one taking it back to its original height and defined width while fading back in its img. .info loads ajax content

<div class="box">
   <img src="#" />
   <div class="info"></div>
</div>
<div class="box">
   <img src="#" />
   <div class="info">Ajax load content</div>
</div>
<div class="box">
   <img src="#" />
   <div class="info">Ajax loads content</div>
</div>

css,我不知道高度.

The css, i don't know the height.

.box {
  width: 230px;
  height: auto;
}

.info {
  height: auto;
  width: auto;
}

我尝试过

$(".box").each(function(){
    var box = $(this);
    box.data('height', $(this).height());
    box.click(function(){
       box.addClass("opened");
       if(box.hasClass("opened"){
           $("img", this).fadeOut("slow", function(){
               box.css("width", "600");
               box.css("height", "500");
               box.removeClass("opened");
           });
       } else { 
           $("img", this).fadeIn("slow");
           box.width(230);
           box.height(box.data('height'));
    });
});

推荐答案

这是我最后的有效代码:

This is my final code which works:

$(function(){
//run the function for all boxes
$(".box").each(function () {
    var item = $(this);
    var thumb = $("a", item);
    var infoBox = $(".info", item);
    thumb.click(function(e) {
        e.preventDefault();
        $(".box").removeClass("opened");
        $(".info").empty();
            $(".box a").fadeIn("slow");
        $(".info").css({
                    "width": "auto",
                    "height": "auto"
                });
        $(".box a").css("width", "230"); 
        $(".box a").css("height", "auto");          
        $(".box").css("width", "230"); 
        $(".box").css("height", "auto");
        item.addClass("opened"); 

        if (item.hasClass("opened")) {
            var url = this.href;
            thumb.fadeOut("slow");
                infoBox.css({
                        "visibility": "visible",
                    "height": "auto"
                });
                infoBox.load(url, function () {
                    var newHeight = infoBox.outerHeight(true);
                    $(".readMore", item).click(function (e) {
                        var selector = $(this).attr('data-filter-all');
                                $('#container').isotope({
                                    filter: selector
                                });
                                $('#container').isotope('reloadItems');
                                return false;
                    });
                    $('<a href="#" class="closeBox">Close</a>"').appendTo(infoBox).click(function (e) {
                                e.preventDefault();
                                $("html, body").animate({scrollTop: 0}, 500);
                                $('#container').isotope('reLayout');
                            });
                    item.animate({
                        "width": "692",
                        "height": newHeight
                    }, 300);
                    thumb.animate({
                                "width": "692",
                                "height": newHeight
                    }, 300);
                    infoBox.animate({width: 692, height: newHeight}, function () {
                                $('#container').isotope('reLayout', function () {
                                    Shadowbox.setup();
                                    item.removeClass("loading");
                                    infoBox.css({
                                            "visibility": "visible"
                                    });
                                        var videoSpan = infoBox.find("span.video");
                            iframe = $('<iframe/>', {
                                            'frameborder': 0,
                                            'class': 'tide',
                                            'width': '692',
                                            'height': '389',
                                            'src': 'http://player.vimeo.com/video/' + videoSpan.data("vimeoid") + '?autoplay=0&api=1'
                            });
                            videoSpan.replaceWith(iframe);

                                });
                    });
            });
            };
        });
});
  });

这篇关于打开扩展/关闭以恢复原始大小,一系列带有img淡入淡出的框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆