jQuery使用技巧

2016-04-12  本文已影响21人  赞鱼鱼

1.禁止页面的右键菜单

$(document).ready(function(){
  $(document).bind("contextmenu",function(e){
    return false
  })
})

2.新窗口打开页面

//<a href="http://zanseven007.github.io" rel="external">open link</a>
$(document).ready(function(){
  $("a[rel$='external']").click(function(){
    this.target='_blank';    
  })
})

3.滚动到指定位置滑动动画

jQuery.fn.scrollTo = function(speed){
  var targetOffset = $(this).offset().top;
  $(html,body).stop().animate({scrollTop: targetOffset}, speed);
}
//使用
 $(#goTop).click(function(){
  $(body).scrollTo(500);
})

4.检测鼠标的右键和左键

$(document).ready(function(){
  $("#demo").mousedown(function(e){
    alert(e.which);   //1 = 鼠标左键 , 2 = 鼠标中键  ,3 = 鼠标右键    
  })
})

5.更新中ing

上一篇 下一篇

猜你喜欢

热点阅读