Статьи

Показывать рекламные места в блогах в случайном порядке

Чтобы сделать это справедливым для всех, кто подписал рекламу jQuery в блоге, я написал изящную небольшую функцию для загрузки рекламы в случайном порядке . В качестве демонстрации также есть кнопка «Перемешать» для создания случайного перемешивания в рекламных местах вручную. Эту функцию можно сделать более настраиваемой, но она выполняет свою работу.

Попробуйте сами (посмотрите на правую боковую панель!).

jquery-blog-ads

Код

//Function to display ads on the jQuery Blog and shuffle (function($) { var displayAds = { ads: { 1: { title: "jQuery UI Widgets for PC, Mobile and Touch devices", href: "http://www.jqwidgets.com", img: "jqwidgets.png" }, 2: { title: "jQuery Chop Slider 2.0 - The most eye catching image slider on the internet!", href: "http://www.idangero.us/cs/", img: "idangerous.jpg" }, 3: { title: "Sauce Labs - Online Cross Browser Testing", href: "http://www.saucelabs.com/scouthome?utm_source=banner&utm_medium=flat&utm_campaign=all+all+banner+jquery4u", img: "sauce-labs.jpg" }, 4: { title: "Diamond Slider - Ken Burns Effect & Unlimited Transitions", href: "http://www.diamond.billykids-lab.net/", img: "diamond-slider.jpg" }, 5: { title: "AJAX Zoom - jQuery Dynamic 2d/360 Degrees Zoom with ipad support.", href: "http://www.ajax-zoom.com", img: "ajax-zoom.jpg" } }, signupAd: { title: "Advertise here", href: "http://www.jquery4u.com/advertise/" }, shuffleAds: function(arr) { for(var j, x, i = arr.length; i; j = parseInt(Math.random() * i), x = arr[--i], arr[i] = arr[j], arr[j] = x); return arr; }, load: function() { $('#shuffle-ads').hide(); var adContainer = $('#jq4u-sidebar-ads').empty(), adsArray = Array(); /* construct ads */ $.each(this.ads, function(i,v) { adsArray.push('  '); }); /* shuffle ads in random order */ adsArray = this.shuffleAds(adsArray); /* output ads */ $.each(adsArray, function(i,v) { adContainer.append(v); }); /* add the signup ad */ adContainer.append(' ' + this.signupAd.title + ' '); /* show shuffle button */ adContainer.append(' Shuffle '); $('#shuffle-ads').live('click', function(e) { e.preventDefault(); displayAds.load(); }); $('#shuffle-ads').show(); } } $(document).ready(function() { displayAds.load(); }); })(jQuery); 
//Function to display ads on the jQuery Blog and shuffle (function($) { var displayAds = { ads: { 1: { title: "jQuery UI Widgets for PC, Mobile and Touch devices", href: "http://www.jqwidgets.com", img: "jqwidgets.png" }, 2: { title: "jQuery Chop Slider 2.0 - The most eye catching image slider on the internet!", href: "http://www.idangero.us/cs/", img: "idangerous.jpg" }, 3: { title: "Sauce Labs - Online Cross Browser Testing", href: "http://www.saucelabs.com/scouthome?utm_source=banner&utm_medium=flat&utm_campaign=all+all+banner+jquery4u", img: "sauce-labs.jpg" }, 4: { title: "Diamond Slider - Ken Burns Effect & Unlimited Transitions", href: "http://www.diamond.billykids-lab.net/", img: "diamond-slider.jpg" }, 5: { title: "AJAX Zoom - jQuery Dynamic 2d/360 Degrees Zoom with ipad support.", href: "http://www.ajax-zoom.com", img: "ajax-zoom.jpg" } }, signupAd: { title: "Advertise here", href: "http://www.jquery4u.com/advertise/" }, shuffleAds: function(arr) { for(var j, x, i = arr.length; i; j = parseInt(Math.random() * i), x = arr[--i], arr[i] = arr[j], arr[j] = x); return arr; }, load: function() { $('#shuffle-ads').hide(); var adContainer = $('#jq4u-sidebar-ads').empty(), adsArray = Array(); /* construct ads */ $.each(this.ads, function(i,v) { adsArray.push(' '); }); /* shuffle ads in random order */ adsArray = this.shuffleAds(adsArray); /* output ads */ $.each(adsArray, function(i,v) { adContainer.append(v); }); /* add the signup ad */ adContainer.append(' ' + this.signupAd.title + ' '); /* show shuffle button */ adContainer.append(' Shuffle '); $('#shuffle-ads').live('click', function(e) { e.preventDefault(); displayAds.load(); }); $('#shuffle-ads').show(); } } $(document).ready(function() { displayAds.load(); }); })(jQuery);
//Function to display ads on the jQuery Blog and shuffle (function($) { var displayAds = { ads: { 1: { title: "jQuery UI Widgets for PC, Mobile and Touch devices", href: "http://www.jqwidgets.com", img: "jqwidgets.png" }, 2: { title: "jQuery Chop Slider 2.0 - The most eye catching image slider on the internet!", href: "http://www.idangero.us/cs/", img: "idangerous.jpg" }, 3: { title: "Sauce Labs - Online Cross Browser Testing", href: "http://www.saucelabs.com/scouthome?utm_source=banner&utm_medium=flat&utm_campaign=all+all+banner+jquery4u", img: "sauce-labs.jpg" }, 4: { title: "Diamond Slider - Ken Burns Effect & Unlimited Transitions", href: "http://www.diamond.billykids-lab.net/", img: "diamond-slider.jpg" }, 5: { title: "AJAX Zoom - jQuery Dynamic 2d/360 Degrees Zoom with ipad support.", href: "http://www.ajax-zoom.com", img: "ajax-zoom.jpg" } }, signupAd: { title: "Advertise here", href: "http://www.jquery4u.com/advertise/" }, shuffleAds: function(arr) { for(var j, x, i = arr.length; i; j = parseInt(Math.random() * i), x = arr[--i], arr[i] = arr[j], arr[j] = x); return arr; }, load: function() { $('#shuffle-ads').hide(); var adContainer = $('#jq4u-sidebar-ads').empty(), adsArray = Array(); /* construct ads */ $.each(this.ads, function(i,v) { adsArray.push(' '); }); /* shuffle ads in random order */ adsArray = this.shuffleAds(adsArray); /* output ads */ $.each(adsArray, function(i,v) { adContainer.append(v); }); /* add the signup ad */ adContainer.append(' ' + this.signupAd.title + ' '); /* show shuffle button */ adContainer.append(' Shuffle '); $('#shuffle-ads').live('click', function(e) { e.preventDefault(); displayAds.load(); }); $('#shuffle-ads').show(); } } $(document).ready(function() { displayAds.load(); }); })(jQuery);
//Function to display ads on the jQuery Blog and shuffle (function($) { var displayAds = { ads: { 1: { title: "jQuery UI Widgets for PC, Mobile and Touch devices", href: "http://www.jqwidgets.com", img: "jqwidgets.png" }, 2: { title: "jQuery Chop Slider 2.0 - The most eye catching image slider on the internet!", href: "http://www.idangero.us/cs/", img: "idangerous.jpg" }, 3: { title: "Sauce Labs - Online Cross Browser Testing", href: "http://www.saucelabs.com/scouthome?utm_source=banner&utm_medium=flat&utm_campaign=all+all+banner+jquery4u", img: "sauce-labs.jpg" }, 4: { title: "Diamond Slider - Ken Burns Effect & Unlimited Transitions", href: "http://www.diamond.billykids-lab.net/", img: "diamond-slider.jpg" }, 5: { title: "AJAX Zoom - jQuery Dynamic 2d/360 Degrees Zoom with ipad support.", href: "http://www.ajax-zoom.com", img: "ajax-zoom.jpg" } }, signupAd: { title: "Advertise here", href: "http://www.jquery4u.com/advertise/" }, shuffleAds: function(arr) { for(var j, x, i = arr.length; i; j = parseInt(Math.random() * i), x = arr[--i], arr[i] = arr[j], arr[j] = x); return arr; }, load: function() { $('#shuffle-ads').hide(); var adContainer = $('#jq4u-sidebar-ads').empty(), adsArray = Array(); /* construct ads */ $.each(this.ads, function(i,v) { adsArray.push(' '); }); /* shuffle ads in random order */ adsArray = this.shuffleAds(adsArray); /* output ads */ $.each(adsArray, function(i,v) { adContainer.append(v); }); /* add the signup ad */ adContainer.append(' ' + this.signupAd.title + ' '); /* show shuffle button */ adContainer.append(' Shuffle '); $('#shuffle-ads').live('click', function(e) { e.preventDefault(); displayAds.load(); }); $('#shuffle-ads').show(); } } $(document).ready(function() { displayAds.load(); }); })(jQuery);
//Function to display ads on the jQuery Blog and shuffle (function($) { var displayAds = { ads: { 1: { title: "jQuery UI Widgets for PC, Mobile and Touch devices", href: "http://www.jqwidgets.com", img: "jqwidgets.png" }, 2: { title: "jQuery Chop Slider 2.0 - The most eye catching image slider on the internet!", href: "http://www.idangero.us/cs/", img: "idangerous.jpg" }, 3: { title: "Sauce Labs - Online Cross Browser Testing", href: "http://www.saucelabs.com/scouthome?utm_source=banner&utm_medium=flat&utm_campaign=all+all+banner+jquery4u", img: "sauce-labs.jpg" }, 4: { title: "Diamond Slider - Ken Burns Effect & Unlimited Transitions", href: "http://www.diamond.billykids-lab.net/", img: "diamond-slider.jpg" }, 5: { title: "AJAX Zoom - jQuery Dynamic 2d/360 Degrees Zoom with ipad support.", href: "http://www.ajax-zoom.com", img: "ajax-zoom.jpg" } }, signupAd: { title: "Advertise here", href: "http://www.jquery4u.com/advertise/" }, shuffleAds: function(arr) { for(var j, x, i = arr.length; i; j = parseInt(Math.random() * i), x = arr[--i], arr[i] = arr[j], arr[j] = x); return arr; }, load: function() { $('#shuffle-ads').hide(); var adContainer = $('#jq4u-sidebar-ads').empty(), adsArray = Array(); /* construct ads */ $.each(this.ads, function(i,v) { adsArray.push(' '); }); /* shuffle ads in random order */ adsArray = this.shuffleAds(adsArray); /* output ads */ $.each(adsArray, function(i,v) { adContainer.append(v); }); /* add the signup ad */ adContainer.append(' ' + this.signupAd.title + ' '); /* show shuffle button */ adContainer.append(' Shuffle '); $('#shuffle-ads').live('click', function(e) { e.preventDefault(); displayAds.load(); }); $('#shuffle-ads').show(); } } $(document).ready(function() { displayAds.load(); }); })(jQuery);