Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    New to the CF scene
    Join Date
    Feb 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    loop in javascript

    In order to integrate the scrollto javascript in a wordpress theme,
    I need to dynamically generate the following script:
    Code:
    $(function(){
    					// Prepare
    					var links = [
    						{
    							id: 'scrollto1',
    							text: 'some text'
    						},
    						{
    							id: 'scrollto2',
    							text: 'some text',
    						},
    						{
    							id: 'scrollto3',
    							text: 'sometext',
    						}
    					];
    
    					// Fetch
    					var $links = $('#scrollto-links');
    
    					// Append Links
    					$.each(links,function(i,link){
    						$('<a>'+link.text+'</a>').click(function(){
    							$('#'+link.id).ScrollTo(link.options);
    						}).appendTo($links);
    					});
    				});
    And this for a X numbers that i will get through counting some posts with a php function I guess.
    I tried the following code without success:
    Code:
    $(function(){
    					// Prepare
    			for		(var i=0;i<6;i++)
    			{
    			links = [
    						{
    							id: 'scrollto',
    							text: 'Scroll to #scrollto'+[i]
    						}
    					];
    }
    					// Fetch
    					var $links = $('#scrollto-links');
    
    					// Append Links
    					$.each(links,function(i,link){
    						$('<a>'+link.text+'</a>').click(function(){
    							$('#'+link.id).ScrollTo(link.options);
    						}).appendTo($links);
    					});
    				});
    Any help is welcome ;-)
    Thanks,
    f
    Last edited by VIPStephan; 02-02-2013 at 09:13 PM. Reason: corrected code BB tags


 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •