欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jQuery縱向?qū)Ш讲藛涡Ч麑崿F(xiàn)方法

 更新時間:2016年12月19日 10:41:02   作者:鬼畜十三  
這篇文章主要介紹了jQuery縱向?qū)Ш讲藛涡Ч麑崿F(xiàn)方法,可實現(xiàn)類似淘寶首頁縱向菜單的顯示效果,涉及jQuery鼠標響應及頁面元素屬性動態(tài)操作相關技巧,需要的朋友可以參考下

本文實例講述了jQuery縱向?qū)Ш讲藛涡Ч麑崿F(xiàn)方法。分享給大家供大家參考,具體如下:

效果如下:

核心代碼如下:

$( document ).ready( function(e){
  var $catCont = $( ".cat-cont" );  //二級菜單div
  var $catList = $( ".J_Cat" );    //一級菜單li
  $catList.on( "mouseenter", function(){
    var index = $( this ).index();
    var $curCatList = $( ".cat-cont-bd>li:eq(" + index + ")" );     //鼠標移上去對應的二級菜單的li
    $catList.removeClass( "selected selected-prev" );
    $( this ).addClass( "selected" ).prev().addClass( "selected-prev" );
    $catCont.show();
    $curCatList.css( "display", "list-item").siblings().css( "display", "none" );
    var viewHeight = $( window ).height();
    var catOffsetTop = $( this ).offset().top - $( window ).scrollTop();
    var catBottomGap = viewHeight - catOffsetTop;
    var catPositionTop = $( this ).position().top;
    var catContHeight = $catCont.height();
    if( catBottomGap >= catContHeight ) {
      $catCont.css( "top", catPositionTop );
    }
    if( catBottomGap < catContHeight && viewHeight >= catContHeight ) {
      $catCont.css( "top", catPositionTop - ( catContHeight - catBottomGap ) - 20 );
    }
    if( catBottomGap < catContHeight && viewHeight < catContHeight ) {
      $catCont.css( "top", catPositionTop );
    }
    if( catBottomGap <= 66 ) {
      $catCont.css( "top", catPositionTop - catContHeight + 33 );
    }
  }).on( "mouseleave", function( event ){
    if( !$( event.relatedTarget ).hasClass( "cat-cont-bd" ) ){  //交互災難:離開一級菜單劃不到二級菜單,如何知道離開一級菜單后進入的是二級菜單?jquery提供屬性:event.relatedTarget(離開后進入的對象)
      $( this ).removeClass( "selected selected-prev" );
      $catCont.hide();
    }
  });
  $catCont.on( "mouseleave", function(){
    $catCont.hide();
    $catList.removeClass( "selected selected-prev" );
  });
});

更多關于jQuery相關內(nèi)容感興趣的讀者可查看本站專題:《jQuery切換特效與技巧總結(jié)》、《jQuery擴展技巧總結(jié)》、《jQuery常用插件及用法總結(jié)》、《jQuery拖拽特效與技巧總結(jié)》、《jQuery表格(table)操作技巧匯總》、《jquery中Ajax用法總結(jié)》、《jQuery常見經(jīng)典特效匯總》、《jQuery動畫與特效用法總結(jié)》及《jquery選擇器用法總結(jié)

希望本文所述對大家jQuery程序設計有所幫助。

相關文章

最新評論