0

我有一个分配给 id´s (#item & #content) 的函数。但是我怎样才能重写它,以便它与类一起工作?

window.addEvent('domready', function() {

    var myVerticalSlide = new Fx.Slide('content');

    $('item').addEvent('click', function(event){
        event.stop();
        myVerticalSlide.toggle();
    });
});
4

2 回答 2

0

If i correctly understood, count of 'item' and count of 'content' will be the same. Try something like it

<script>
    window.addEvent('domready', function() {
        $$('.item').each(function(el,ind){
            new Fx.Slide($$('.content')[ind]).hide();
            el.addEvent('click', function(event){
                event.stop();
                var myVerticalSlide = new Fx.Slide($$('.content')[ind]).toggle();
            }); 
        })
    });
</script>
于 2013-03-07T15:29:03.817 回答
0

这是整个代码:

    <style type="text/css">
    .wrapper{
        max-width:613px;
        float:left;
        position:relative;
    }
    .new { 
        border: solid 1px #ddd; 
        padding: 5px; 
        float:left;
        max-width:660;
        min-width:320px;
    }
    .item{
        width:120px;
        padding:10px;
        display:block;
        background-color:#CCC;
        float:left;
        margin:5px;
    }
    .content{
        padding:10px;
        height:80px;
        visibility:hidden;
    }
    .item:hover > .content{

    }
    .full{
        position:absolute;
        width:100%;
        display:block;
        height:100px;
        background-color:#666;
        left:0px;
    }
  </style>

<script type='text/javascript'>//<![CDATA[ 

window.addEvent('load', function() {
(function(){
    var wrap,
        overview = document.getElement('div.overview');

    overview.getElements('div.item').each(function(a, i){
        if (i % 4 == 0){
            wrap && overview.adopt(wrap);
            wrap = new Element('div.new');
        }
        wrap.adopt(a);
    });

    overview.adopt(wrap);
}());
});
window.addEvent('domready', function() {
        $$('.item').each(function(el,ind){
            new Fx.Slide($$('.content')[ind]).toggle();
            el.addEvent('click', function(event){
                event.stop();
                var myVerticalSlide = new Fx.Slide($$('.content')[ind]).toggle();
            }); 
        })
    });//]]>  
</script>
</head>
<body>
<div class="wrapper">
    <div class="overview">
        <div  class="item">Test1
        <div  class="content">
            <div class="full">
                <p>Content1</p>
            </div>
        </div>
        </div>
        <div class="item">Test2
        <div class="content">
            <div class="full">
                <p>Content2</p>
            </div>
        </div></div>
        <div class="item">Test3
        <div class="content">
            <div class="full">
                <p>Content3</p>
            </div>
        </div></div>
        <div class="item">Test4
        <div class="content">
            <div class="full">
                <p>Content4</p>
            </div>
        </div></div>
        <div class="item">Test5
        <div class="content">
            <div class="full">
                <p>Content5</p>
            </div>
        </div></div>
        <div class="item">Test6
        <div class="content">
            <div class="full">
                <p>Content6</p>
            </div>
        </div></div>
        <div class="item">Test7
        <div class="content">
            <div class="full">
                <p>Content7</p>
            </div>
        </div></div>
        <div class="item">Test8
        <div class="content">
            <div class="full">
                <p>Content8</p>
            </div>
        </div></div>
        <div class="item">Test9
        <div class="content">
            <div class="full">
                <p>Content9</p>
            </div>
        </div></div>
        <div class="item">Test10
        <div class="content">
            <div class="full">
                <p>Content10</p>
            </div>
        </div></div>
        <div class="item">Test11
        <div class="content">
            <div class="full">
                <p>Content11</p>
            </div>
        </div></div>
    </div>
</div>

另一件事是,当我单击第一个 div 时,它会打开,之后,当我单击第二个 div 时,它也会打开,但是当我单击第二个 div 时,第一个 div 应该关闭。

于 2013-03-08T06:53:29.070 回答