2013-03-07 51 views
0

我收到了分配給id的函數(#item &#內容)。 但我怎麼能重寫它,以便它與類一起工作?更改mootools函數,id到類?

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

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

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

回答

0

如果我正確理解,'item'的計數和'content'的計數將是相同的。嘗試類似的東西

<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> 
+0

謝謝,我該如何改變狀態?這就是它的全部關閉,當我點擊,它打開? – fr3d 2013-03-07 16:10:51

+0

我已經添加了一行'new Fx.Slide($$('。content')[ind])。hide();' ,試一試吧 – wearwoolf 2013-03-07 16:14:10

+0

看起來不錯,但是當我刷新頁面時,div是短時間打開的,並且比它們關閉 – fr3d 2013-03-07 16:17:22

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時。