美文网首页
jQuery Scenario

jQuery Scenario

作者: westmoor | 来源:发表于2015-06-04 15:01 被阅读0次
  • Check if a checkbox is checked. often used on agreement dialog
    demo(checkbox)

  • Check if elements are visible
    $category.is(":visible")

  • Even if jQuery select element that doesn't exist, it would not report error.
    so when check if an element exists
    cannot use this method

if ($("#id")){
    // do stuff
}

Should check its length

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

hover functions

$("#foo").hover(function(){
 // do stuff
}, function(){
    // do stuff
});
  • Difference between window.onload and $(document).ready()
    The ready event occurs after the HTML document has been loaded, while the onload event occurs later, when all content(eg. images) also has been loaded

  • Why use .bind() over .click() or any other event?
    They're effectively the same, using bind() allows you to make use of namedspaced events This is especially useful when writing plugins.
    and also yo ucan use multiple events

$("#foo").bind('mouseenter mouseleave', function(){
    $(this).toggleClass('entered');
});
  • event bubbling and event.stopPropagation()
    The concept of 'bubbling up ' is like if you have a child element with a click event and you don't want it to trigger the click event of the parent. You can use event.stopPropagation()
$("#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.

  • event capturing

Animation

  • Check if element is in animation
    if($("#foo").is(":animated"))
  • stop() is useful when dealing with starting animation when previous one is not finished.
    (otherwise, the new animation will wait for previous one to finish in queue).
$("#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};

相关文章

  • jQuery Scenario

    Check if a checkbox is checked. often used on agreement d...

  • Android Activity Scenario总结

    Android Activity Scenario总结 Activity Scenario参考文档[https:/...

  • Love scenario

    警告:不要因为这个年纪的狭隘眼界见到一些卑劣不堪的人格就自命清高 不要因为如此而悲天悯人 愤世嫉俗 多的是你不知道...

  • Scenario,以柔克刚

    建筑课堂的重构设计终于到了收尾,整个过程历时8个月,从用研到最终的细节设计delivery,可谓是目标导向设计过程...

  • Scenario - 健身

    One of the purposes I am in Singapore is to keep fitness....

  • Scenario - 衣

    Scenario 1: 某天,穿着新买的高跟鞋去上班,刚到办公室,就遇到一个来自Romania的女生,对话就这样开...

  • Scenario - 行

    HikingLast Saturday (2019-07-20), we went to MacRitchie R...

  • Scenario - 食

    Food,include breakfast, lunch, brunch, dinner, different ...

  • Scenario - 住

    Village Residence Clark QuayIt's an awesome apartment wit...

  • Test scenario

    相信大家 test case (测试用例) 就应该听得比较多,又有没有听过 test scenario 呢?我在一...

网友评论

      本文标题:jQuery Scenario

      本文链接:https://www.haomeiwen.com/subject/cwpdqttx.html