开发者

How can I make my anchor tag (this)

I've run into a small problem, Ive got a page full of anchor tags and when 1 of them is selected an animation begins, my only problem right now is that I havent defined the anchor tag as (this) so when a series of anchors are selected each of them perform the animation, im not sur right now how I can change the a tag to this though?

My code so far is:

$('a').bind('click', function(e){
            $ajax = $('<div id="ajax"></div>');开发者_如何学JAVA
            $ajax.prependTo('#container');
            $('html, body').animate({ scrollTop: 0 }, 'fast', function(){
                $ajax.animate({ height: 300 }, 'slow', function(){ 
                    $preloader = $('<div id="preloader"></div>').hide();
                    $preloader.prependTo('#ajax').fadeIn('normal');
                });
            });
            e.preventDefault();
        });


you want to add an id to your anchor tag like this

<a id="myTag" href=""></a>

Then you can access it like this

$('#myTag').bind(...

You should only use an id once per page (meaning that every id is unique, not that there can only be 1 id per page).

Here's some more info on the id-selector from Jquery and more selectors in general


You do not use var keywords. This is bad, as all variables you create this way are in the global scope overwriting each other

$('a').bind('click', function(e){
    var $ajax = $('<div></div>').prependTo('#container');

    $('html, body').animate({ scrollTop: 0 }, 'fast', function(){
        $ajax.animate({ height: 300 }, 'slow', function(){ 
            $('<div></div>').hide().prependTo($ajax).fadeIn('normal');
            // you can refer to $ajax here! --^^^^^
        });
    });
    e.preventDefault();
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜