开发者

using .delegate function in slide show

开发者 https://www.devze.com 2023-04-11 19:49 出处:网络
I have a script that runs a slideshow for my page. I\'m trying to use .delegate() to insert a new set of images shown within the slideshow including its thumbnails. I\'m using a .load() function to lo

I have a script that runs a slideshow for my page. I'm trying to use .delegate() to insert a new set of images shown within the slideshow including its thumbnails. I'm using a .load() function to load an external <div> to replace some HTML within the active page. I also have buttons with IDs, (#kick1, #kwick2, etc.) that determine what set of slide show is loaded.

 jQuery("#kwick2").click(function (开发者_C百科) {
     jQuery("body").delegate('#slideshow', 'click', function() {
         jQuery('#slideshow').load('/design.html #design');      
     )};
 )};

Pretty sure the syntax is all wrong. Can someone help me?

The #slideshow div is something I created to contain some other divs directly effected by the slideshow script. Within div ID #slideshow are

<div class="main_image">, <div class="desc"> and <div class="image_thumb">.

These are being replaced directly when you click a KWICK button, they are all pretty much self explanatory, image thumb has and unordered list with image links.


You should not re-deligate every time you click the button. You are doing the wrong.

Instead what you should have is something like:

var foobar = (function () {

   var func , mod1 , mod2;
   mod1 = function () {
      /* do something in state 1 */
   };
   mod2 = function () {
     /* do something in state 2 */
   };

   return {
      state: function (e) {
         switch (this.id){
            case 'kwick1':
               func = mod1;
               break;
            case 'kwick2':
               func = mod2;
               break;
         }
      },
      callback: function (e) {
         func.call();
      }
   }
})();

jQuery("#kwick1").click( foobar.state ); // and you really should delegate this
jQuery("#kwick2").click( foobar.state );
jQuery("body").delegate('#slideshow','click', foobar.callback);

Or something similar to this ..

And no , i did not test this code. It is written to explain the concept, not to spoon-feed people.


not sure if i have understood the question well, anyway you have to specify what event you are delegating

 jQuery("#kwick2").click(function () {
 jQuery("body").delegate('#slideshow',"click", function(){
    jQuery('#slideshow').load('/design.html #design');      
    )};
 )};

delegate

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号