jQuery Scenario

2015-06-04  本文已影响0人  westmoor
if ($("#id")){
    // do stuff
}

Should check its length

if($("#id").length > 0){
    // do stuff
}
$toggleBtn.toggle(function(){
    // show element
    }, function(){
    // hide element
})

hover functions

$("#foo").hover(function(){
 // do stuff
}, function(){
    // do stuff
});
$("#foo").bind('mouseenter mouseleave', function(){
    $(this).toggleClass('entered');
});
$("#foo").bind('click', function(event) {
    // do stuff
    event.stopPropagation();
});

similar is preventDefault() method. You first create event in function and use it to call methods.


Animation

$("#foo").hover(function(){
    $(this).stop()
                .animate({height:"150", width: "300"}, 200);
}, function() {
    $(this).stop()
                .animte({height:"22", width:"60"}, 300};

if animation is a combo

$("#foo").hover(function(){
    $(this).stop(true)  // means clear the queue
                .animate({height:"150", width: "300"}, 200);
                .animate({blabla}, 300);
}, function() {
    $(this).stop()
                .animte({height:"22", width:"60"}, 300};
上一篇 下一篇

猜你喜欢

热点阅读