jquery仿百度经验滑动切换浏览效果

 更新时间:2015年04月14日 11:59:04   投稿:hebedich  
本文给大家分享的是使用jQuery实现仿百度经验华东切换浏览效果,非常的炫酷,推荐给大家。有需要的小伙伴可以参考下

jquery仿百度经验滑动切换浏览效果

$(function() {
  wordStrong();
  $("#content ul").width($("#content ul li:first").width()*$("#content ul li").length);
  $("#header .top_right .vote").hover(function() {
    $(this).children(".hover-tip").css("display", "block");
    $(this).children(".num").css("display", "none");  
  }, function() {
    $(this).children(".hover-tip").css("display", "none");
    $(this).children(".num").css("display", "block");  
  });
   
   
  $("#content .left, #content .right").width(($(document).width()-$("#content").width())/4);
  $("#content .left").css("left", -$("#content .left").width());
  $("#content .right").css("right", -$("#content .right").width());
   
  var showId = 0;
  $("#content span.left").hover(function() {
    if ( checkFirst() ) return ;
    $(this).css("cursor", "pointer");
    $(this).siblings(".sl").stop().animate({
      opacity:0.5 
    }); 
  }, function() {
    $(this).siblings(".sl").stop().animate({
      opacity:0
    }); 
  }).click(function() {
    if ( checkFirst() ) return ;
    showId --;
    $("#content").attr("showId", showId);
    $("#footer li").children().removeClass("active").end().children().eq(showId).addClass("active");
    center(showId);
  });
   
  $("#content span.right").hover(function() {
    if ( checkLast() ) return ;
    $(this).css("cursor", "pointer");
    $(this).siblings(".sr").stop().animate({
      opacity:0.5
    }); 
  }, function() {
    $(this).siblings(".sr").stop().animate({
      opacity:0
    }); 
  }).click(function() {
    if ( checkLast() ) return ;  
    showId ++;   
    $("#content").attr("showId", showId);
    $("#footer li").children().removeClass("active").end().children().eq(showId).addClass("active");
    center(showId); 
  });
   
  function checkFirst() {
    if ( $("#content").attr("showId") == 0 ) {
      $("#content span.left").css("cursor", "default");
      return true;    
    }
    return false;
  }
   
  function checkLast() {
    if ( $("#content").attr("showId") == $("#content ul li").length-1 ) {
      $("#content span.right").css("cursor", "default");
      return true;    
    }
    return false;  
  }
     
  /* 首字母大写 */
  function wordStrong() {
    var liList = $("#content ul li");
    for (var j = 0; j < liList.length; j ++) {
      var pList = $("#content .cont_"+(j+1)+" .cont_word p");
      for (var i = 0; i < pList.length; i ++) {
        var p = pList.get(i);
        var pCont = $(p).html();    
        var s = $("<b>"+(i+1)+"</b>");
        s.css("font-size", "24px");   
        $(p).html('');
        s.appendTo(p);
        $(p).append(pCont.substring(1));    
      }
    }
  }  
   
  center(0);
   
  //相对li居中
  function center(liIndex) {
    var li = $("#content ul li").css("opacity", 0.3).eq(liIndex).css("opacity", 1);
    $("#content ul").animate({
      left: (-li.width()*liIndex)
    });
  }
   
  var footLen = $("#content ul li").length;
  var foots = $("#footer ul");
  for (var i = 1; i < footLen-1; i ++) {
    var childA = $("<a>").html(i);
    childA.attr("href", "#");
    $("<li>").append(childA).insertBefore(foots.children("[step=last]")).attr("step", i);   
  }
  foots.children(":last").attr("step", footLen-1);
  foots.css("left", ($(window).width()-foots.width())/2); 
  $("#footer li").click(function() {
    $("#footer ul li").children().removeClass("active");
    $(this).children().addClass("active");
    center($(this).attr("step"));
  });
   
  function myAddEvent(obj, e, fn) {
    if ( obj.attachEvent ) {
      obj.attachEvent('on'+e, fn);
    }else obj.addEventListener(e, fn, false);
  }
   
  function onMouseWheel(ev) { 
    var ev = ev||event;   
    //IE
    //wheelDelta  下滚:负, 上滚:下
    //alert(oEvent.wheelDelta);
    //FF
    //detail:  下滚:正, 上滚: 负
    //alert(oEvent.detail)   
    var bDown = true;
    if ( ev.wheelDelta ) {
      bDown = ev.wheelDelta<0;
    }else {
      bDown = ev.detail>0;
    }    
    if ( !bDown ) {
      if ( checkFirst() ) return ;
      showId --;     
    }
    else {
      if ( checkLast() ) return ;
      showId ++;     
    }
    $("#content").attr("showId", showId);
    $("#footer ul li").children().removeClass("active").end().eq(showId).children().addClass("active");
    center(showId);
    if ( oEvent.preventDefault ) {
      oEvent.preventDefault();
    }
    return false;
  }
   
  myAddEvent(window, 'mousewheel', onMouseWheel);
  myAddEvent(window, 'DOMMouseScroll', onMouseWheel);
});

以上所述就是本文给大家介绍的全部内容了,希望大家能够喜欢。

相关文章

  • jQuery+ajax读取并解析XML文件的方法

    jQuery+ajax读取并解析XML文件的方法

    这篇文章主要介绍了jQuery+ajax读取并解析XML文件的方法,涉及jQuery的ajax方法调用xml文件及针对xml数据的遍历与节点操作相关技巧,需要的朋友可以参考下
    2016-09-09
  • jQuery选择器之属性过滤选择器详解

    jQuery选择器之属性过滤选择器详解

    这篇文章主要为大家详细介绍了jQuery选择器之属性过滤选择器,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2017-09-09
  • jquery滚动加载数据的方法

    jquery滚动加载数据的方法

    这篇文章主要介绍了jquery滚动加载数据的方法,实例分析了jQuery动态加载数据的技巧,具有一定参考借鉴价值,需要的朋友可以参考下
    2015-03-03
  • JQuery样式与属性设置方法分析

    JQuery样式与属性设置方法分析

    这篇文章主要介绍了JQuery样式与属性设置方法,结合实例形式分析了jQuery属性的获取与设置、以及样式的添加与删除相关操作技巧,需要的朋友可以参考下
    2019-12-12
  • 分享20款好玩的jQuery游戏

    分享20款好玩的jQuery游戏

    jQuery是时下最流行的 JavaScript 库。现在,除了HTML5以外,也有很多jQuery爱好者使用jQuery来开发游戏,虽然效果没有Flash那么好,但是这些游戏也看起来很酷。
    2011-04-04
  • jQuery ajax应用总结

    jQuery ajax应用总结

    Ajax在Web应用中的作用越来越大,许多工具都包含了对这一功能的使用,以下是对这些常用工具中Ajax的典型实例.
    2016-06-06
  • 轻松学习jQuery插件EasyUI EasyUI创建CRUD应用

    轻松学习jQuery插件EasyUI EasyUI创建CRUD应用

    这篇文章主要帮大家轻松学习jQuery插件EasyUI,并利用EasyUI创建CRUD应用,感兴趣的小伙伴们可以参考一下
    2015-11-11
  • JQuery选择器用法详解

    JQuery选择器用法详解

    本文详细讲解了JQuery选择器的用法,文中通过示例代码介绍的非常详细。对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2022-04-04
  • jQuery对象数据缓存Cache原理及jQuery.data方法区别介绍

    jQuery对象数据缓存Cache原理及jQuery.data方法区别介绍

    jQuery.data(..)来实现数据缓存,但有两个用户经常使用的data([key],[value])和jQuery.data(element,[key],[value]),接下来为大家介绍下他们的区别,感兴趣的朋友可以参考下哈
    2013-04-04
  • Eclipse下jQuery文件报错出现错误提示红叉

    Eclipse下jQuery文件报错出现错误提示红叉

    工程中加入jquery.xx.js文件,发现该文件出现错误提示(红×),但使用Eclipse 3.7以前的版本就不会出现这种提示,下面有个不错的解决方法,大家可以参考下
    2014-01-01

最新评论