美文网首页
jQuery使用技巧

jQuery使用技巧

作者: 赞鱼鱼 | 来源:发表于2016-04-12 17:04 被阅读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

相关文章

网友评论

      本文标题:jQuery使用技巧

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