开发者

JQuery how to run script on button press

开发者 https://www.devze.com 2023-03-15 05:10 出处:网络
What I\'m doing is making a theme with two layouts, which are changeable by button press, from standard blog layout to a gallery layout etc.

What I'm doing is making a theme with two layouts, which are changeable by button press, from standard blog layout to a gallery layout etc.

However I wan't to run the infinite scroll script when the button is pressed for the gallery layout, everything works except for infinite scroll.

How can I run another script along with this? Kinda like taking away the <!-- / --> around a script to activate it, if you know what I mean.

$("a.button").toggle(function() {
        $(this).addClass("toggle");
        $("div.posts").fadeOut("fast", function() {
            $(this).fadeIn("fast").addClass("gallery");
        });
    }, function() {
        $(this).removeClass("toggle");开发者_运维问答
        $("div.posts").fadeOut("fast", function() {
            $(this).fadeIn("fast").removeClass("gallery");
        });
    }); 
});


It would be better if you initialize both layouts on page load (DOM Ready) and just toggle them via CSS display property. The main reason for that is that you wouldn't need to re-initialize the infinite scroll object each time, and destroy it when user toggles back to blog style.


If you want to use <a> tag then you have to use:

$('a').click(function(){
    ... scroll code...
});

and if you want to access it by an ID then use like this:

   $('#anyId').click(function(){
    ... scroll code...
});


$('.gallery').click(function(){
    ... scroll code...
});

Adding a click listener just to the gallery class. Will that work?

0

精彩评论

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

关注公众号