Что нового

Помогите с js

  • Автор темы Автор темы antojjk
  • Дата начала Дата начала
A

antojjk

Гость
Есть 6 окон с текстом, нажимаешь на 1, 2, 3, 4, 5, 6 оно раскрываеться. Как сделать чтобы, если ты открыл 2 окно, 1 окно свернулось?
 
Цитата: antojjkКак сделать чтобы, если ты открыл 2 окно, 1 окно свернулось?что бы ответить на этот вопрос, нужно видеть код
 
antojjk,без кода, могу сказать единственное - проверкой на display: block других окон.
 
<p onclick="openmore3(this);" class="slide"><span>Развернуть</span></p> Показать / Скрыть текстfunction rotateBlock(id, timeFade, timeChange){    this.id = id;        var el = $('#' + this.id),        img = el.find('img'),            current = 0,        count = img.length,        stop = false,        change;            if (count < 2) return false;        var show = function(n){            img.removeClass('active').removeClass('preactive').css('opacity', 1);            img.eq(n).addClass('active');                        var imgNext = img.eq(n).parent().next('a').find('img');                        (imgNext.length != 0) ? imgNext.addClass('preactive') : img.eq(0).addClass('preactive');                    },                showNext = function(){            current++;            if (current == count ) current = 0;            img.eq(current - 1).stop().animate( {'opacity':0} , timeFade , function(){                show(current);            });        },                run = function(){            if (!stop){                showNext();                change = setTimeout(run, timeChange);            }        },                goFrom = function(n){            show(;n);            change = setTimeout(run, timeChange);        };                goFrom(current);    }var imgsrc = '';$(window).ready(function(){/*    $('.chs img').hover(        function () {            imgsrc = $(this).attr("src");            var src = imgsrc.substr(0,imgsrc.length-6) + 'color' + imgsrc.substr(-4);            $(this).attr("src",src);        },         function () {            $(this).attr("src",imgsrc);        }    );*/        $('.icons img.icon, .icons div.absbubble').hover(            function () {                if($(this).hasClass('icon')){                    imgsrc = $(this).attr("src");                    //var src = imgsrc.substr(0,imgsrc.length-4) + 'hov' + imgsrc.substr(-4);                    //$(this).attr("src",src);                    $(this).next().css("display", "block");                    }else if($(this).hasClass('absbubble')){                    $(this).css("display";, "block");                }            },             function () {                if($(this).hasClass('icon')){                    $(this).attr("src",imgsrc);                    $(this).next().css("display", "none");                    }else if($(this).hasClass('absbubble')){                    $(this).css("display";, "none");                }            }    );        $('.rate .ratestars, .rate div.bubble2, .b-best .ratestars, .b-best div.bubble2').hover(            function () {                if($(this).hasClass('ratestars'));{                    $(this).next().css("display", "block");                    }else if($(this).hasClass('bubble2')){                    $(this).css("display";, "block");                }            },             function () {                if($(this).hasClass('ratestars'));{                    $(this).next().css("display", "none");                    }else if($(this).hasClass('bubble2')){                    $(this).css("display";, "none");                }            }    );                    //    $(".flboxbg #clickslide").click(function () {//        if($(this).parent().hasClass("open")){//            $(this).next().hide("slide", { direction: "right" }, 5000, function () {$(this).parent().removeClass("open");});//        }else{//            $(this).next().show("slide", { direction: "right" }, 5000, function () {$(this).parent().addClass("open");});//        }//    });        //    $(".flboxbg #clickslide").click(function () {//    $(this).next().hide("slide";, { direction: "right" }, 1000);//    $(this).parent().removeClass("open").addClass("close");//});////$(".flboxbg .close #clickslide").click(function () {////console.info(1);////$(this).next().show("slide", { direction: "left" }, 1000);////$(this).parent().removeClass("close").addClass("open");////});////$(".flboxbg #clickslide").click(function () {//if($(this).parent().hasClass("open")){//    $(this).parent().animate({"margin-right": "-210px"}, 1000, function () {$(this).parent().removeClass("open")});////    $(this).parent().animate({"margin-right": "-210px"}, 1000, .removeClass("open"));//}else{//    $(this).parent().animate({"margin-right": "0px"}, 1000, function () {$(this).parent().addClass("open")});////    $(this).parent().animate({"margin-right": "0px"}, 1000, .addClass("open"));//}//    ////console.info(2);////$(this).next().hide("slide", { direction: "right" }, 1000);////$(this).parent().removeClass("open").addClass("close");//});        $(".flboxbg #clickslide").click(function () {        if($(this).parent0;).hasClass("open")){            $(this).parent().removeClass("open");        }else{            $(this).parent().addClass("open");        }    });        function calculateTotal() {        var n = $("input:checked");        var total = 0;        for (var i = 0; i < n.length; i++) {            if($(n[i]).parent().parent().find('.realprice').length>0){                total += parseInt($(n[i]).parent().parent().find('.realprice').html());                            }        }        $("#totalprice").html(total + ' руб.');    }    $(".packets .checkbox").click(calculateTotal);    calculateTotal();});function openmore(obj){    if(obj.innerHTML.toLowerCase() == "<span>развернуть</span>"){        obj.innerHTML = "<span>Свернуть</span>";        $(obj).parent().parent().parent().parent().addClass("open");        var arr = $($(obj).parent().par
 
Все на много проще.<script>function show_hide(id) {    $('._block').hide();    $('#block-' + id).show();}</script><div id="block-1" class="_block">...</div><div id="block-2" class="_block" style="display: none;">...</div><div id="block-3" class="_block" style="display: none;">...</div><div id="block-4" class="_block" style="display: none;">...</div><a href="javascript:" onclick="show_hide(1)">1</a><a href="javascript:" onclick="show_hide(2)">2</a><a href="javascript:" onclick="show_hide(3)">3</a><a href="javascript:" onclick="show_hide(4)">4</a>
 
Верх