Ver Mensaje Individual
  #2 (permalink)  
Antiguo 30/05/2011, 03:10
quimfv
Colaborador
 
Fecha de Ingreso: marzo-2008
Ubicación: Sabadell
Mensajes: 4.897
Antigüedad: 16 años, 9 meses
Puntos: 574
Respuesta: ¿Cómo colocar dos veces el mismo Scroller?

Como su nombre indica los id deben ser únicos

id -> identificador

luego hay que tocar los scripts para que actuen sobre ellos
Código HTML:
Ver original
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  2. <title>News Slider</title>
  3.  
  4. <style type='text/css'>
  5.     .single_news_container1,
  6.     .single_news_container2 {
  7.         display:none; /* IMPORTANT: hide all the news containers */
  8.     }
  9.     body { font-family: 'Arial'; } /* just styling */
  10.    
  11.     .single_news_container h3,
  12.     .single_news_container2 h3 { padding:0px; margin:0px; margin-bottom:10px; }
  13.    
  14.     #news_navigation1,
  15.     #news_navigation2{
  16.     font-size:20px;
  17.     text-align:center;
  18.     padding:5px;
  19.     background-color: #000;
  20.     color:white;
  21. }
  22.    
  23.     #all_news_container1, #all_news_container2 { padding:10px; color:black; height:200px; border:1px solid #336499;}
  24.    
  25.     #wrapper, #wrapper2 { width:400px;  }
  26.  
  27. <script type='text/javascript' src='js/jquery.js'></script>
  28.  
  29. <script type='text/javascript'>      
  30. var scrollers_No=2;
  31.  
  32. $(document).ready(function(){
  33.     var news_No= new Array();
  34.     var prev_html = '&lt;&lt';
  35.     var next_html = '&gt;&gt;';
  36.  
  37.     for (i=1;i<=scrollers_No;i++){
  38.        $('.single_news_container'+i+':first').fadeIn(100);
  39.        $('.single_news_container'+i+':first').addClass('news_visible'+i);
  40.         news_No[i]= $('.single_news_container'+i).length;  
  41.        $('#news_navigation'+i).html('<a href="javascript:prev_news('+i+');">' + prev_html + '</a> <span id="current_news_num'+i+'">1</span>/<span id="max_news_num'+i+'">' + news_No[i] +'</span><a href="javascript:next_news('+i+');">' + next_html + '</a>');
  42.     }
  43.        
  44.        
  45. });
  46.  
  47.  
  48. function prev_news(scroller){
  49.        
  50.             if($('.news_visible'+scroller).prev('.single_news_container'+scroller).length){
  51.            
  52.                 $('.news_visible'+scroller).fadeOut(100, function(){
  53.                     $('.news_visible'+scroller).removeClass('news_visible'+scroller).prev('.single_news_container'+scroller).addClass('news_visible'+scroller).fadeIn(100);
  54.                     var current = parseInt($('#current_news_num'+scroller).text());
  55.                     if(current>1) $('#current_news_num'+scroller).text(current - 1);
  56.                 });
  57.             }    
  58.            
  59. }
  60.  
  61.  
  62. function next_news(scroller){
  63.             if($('.news_visible'+scroller).next('.single_news_container'+scroller).length){
  64.                 $('.news_visible'+scroller).fadeOut(100, function(){
  65.                     $('.news_visible'+scroller).removeClass('news_visible'+scroller).next('.single_news_container'+scroller).addClass('news_visible'+scroller).fadeIn(100);
  66.                     var current = parseInt($('#current_news_num'+scroller).text());
  67.                     var maxNews = parseInt($('#max_news_num'+scroller).text());
  68.                     if(current<maxNews) $('#current_news_num'+scroller).text(current + 1);
  69.                });
  70.            }  
  71. }
  72.  
  73.  
  74. </head>
  75.  
  76. <!--START THE DIV THAT WILL WRAP IT ALL UP-->
  77.  
  78. <div id='wrapper'>
  79.    
  80.     <!--START THE DIV THAT HOLDS ALL THE NEWS CONTAINERS-->
  81.     <div id='all_news_container1'>
  82.        
  83.         <!--START SINGLE NEWS CONTAINER-->
  84.         <div class='single_news_container1'>
  85.        
  86.             <!--PUT THE TITLE-->
  87.             <h3>Megaupload</h3>
  88.  
  89.            
  90.             <!--AND THE CONTENT-->
  91.             <p><A HREF="http://www.megaupload.com/?d=31C787YE" TARGET="_new">http://www.megaupload.com/?d=31C787YE</A> <A HREF="http://www.megaupload.com/?d=31C787YE" TARGET="_new">http://www.megaupload.com/?d=31C787YE</A></p>
  92.            
  93.         </div>
  94.         <!--END SINGLE NEW CONTAINER-->
  95.        
  96.         <!--AND REPEAT IT HOW MUCH TIMES YOU WANT...-->
  97.         <div class='single_news_container1'>
  98.             <h3>Why do we use it?</h3>
  99.  
  100.             <p><A HREF="http://www.megaupload.com/?d=31C787YE" TARGET="_new">http://www.megaupload.com/?d=31C787YE</A> <A HREF="http://www.megaupload.com/?d=31C787YE" TARGET="_new">http://www.megaupload.com/?d=31C787YE</A></p>
  101.         </div>
  102.        
  103.         <div class='single_news_container1'>
  104.             <h3>Where does it come from?</h3>
  105.             <p>Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur.</p>
  106.         </div>
  107.  
  108.        
  109.         <div class='single_news_container1'>
  110.             <h3>Where can i get some?</h3>
  111.             <p>There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text.</p>
  112.         </div>
  113.        
  114.         <div class='single_news_container1'>
  115.             <h3>The standard Lorem Ipsum passage, used since the 1500s</h3>
  116.             <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.</p>
  117.  
  118.         </div>
  119.         <!--DONE WITH SINGLE NEWS CONTAINERS-->
  120.        
  121.            
  122.     </div>
  123.     <!--END THE DIV THAT HOLDS ALL THE NEWS CONTAINERS-->
  124.  
  125.     <!--AN EMPTY DIV WHERE JQUERY MADE NAVIGATION WILL BE-->
  126.     <div id='news_navigation1'></div>
  127.  
  128. </div>
  129.  
  130. <p>&nbsp;</p>
  131.  
  132.  
  133. <div id='wrapper2'>
  134.  
  135.    
  136.     <!--START THE DIV THAT HOLDS ALL THE NEWS CONTAINERS-->
  137.     <div id='all_news_container2'>
  138.        
  139.         <!--START SINGLE NEWS CONTAINER-->
  140.         <div class='single_news_container2'>
  141.        
  142.             <!--PUT THE TITLE-->
  143.             <h3>Rapidshare</h3>
  144.            
  145.             <!--AND THE CONTENT-->
  146.  
  147.             <p><A HREF="http://www.megaupload.com/?d=31C787YE" TARGET="_new">http://www.megaupload.com/?d=31C787YE</A> <A HREF="http://www.megaupload.com/?d=31C787YE" TARGET="_new">http://www.megaupload.com/?d=31C787YE</A></p>
  148.            
  149.         </div>
  150.         <!--END SINGLE NEW CONTAINER-->
  151.        
  152.         <!--AND REPEAT IT HOW MUCH TIMES YOU WANT...-->
  153.         <div class='single_news_container2'>
  154.             <h3>Why do we use it?</h3>
  155.             <p><A HREF="http://www.megaupload.com/?d=31C787YE" TARGET="_new">http://www.megaupload.com/?d=31C787YE</A> <A HREF="http://www.megaupload.com/?d=31C787YE" TARGET="_new">http://www.megaupload.com/?d=31C787YE</A></p>
  156.  
  157.         </div>
  158.        
  159.         <div class='single_news_container2'>
  160.             <h3>Where does it come from?</h3>
  161.             <p>Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur.</p>
  162.         </div>
  163.        
  164.         <div class='single_news_container2'>
  165.             <h3>Where can i get some?</h3>
  166.  
  167.             <p>There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text.</p>
  168.         </div>
  169.        
  170.         <div class='single_news_container2'>
  171.             <h3>The standard Lorem Ipsum passage, used since the 1500s</h3>
  172.             <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.</p>
  173.         </div>
  174.         <!--DONE WITH SINGLE NEWS CONTAINERS-->
  175.  
  176.        
  177.            
  178.     </div>
  179.     <!--END THE DIV THAT HOLDS ALL THE NEWS CONTAINERS-->
  180.  
  181.     <!--AN EMPTY DIV WHERE JQUERY MADE NAVIGATION WILL BE-->
  182.     <div id='news_navigation2'></div>
  183.  
  184. </div>
  185.  
  186. <!--END THE WRAPPING DIV-->
  187.  
  188. </body>
  189. </html>


Seguro que hay formas mas elegantes de resolverlo... pero así funciona.
__________________
Quim
--------------------------------------------------
Ayudar a ayudar es una buena práctica!!! Y da buenos resultados.

Última edición por quimfv; 30/05/2011 a las 08:15