首页 > Web开发 > 详细

开发中可能会用到的几个 jQuery 小提示和技巧

时间:2014-03-11 14:05:38      阅读:603      评论:0      收藏:0      [点我收藏+]

1、禁止右键

  

1
2
3
4
5
6
7
8
9
10
$(document).ready(function() {
    //catch the right-click context menu
    $(document).bind("contextmenu",function(e) {               
        //warning prompt - optional
        alert("No right-clicking!");
  
        //delete the default context menu
        return false;
    });
});

 2、文本缩放

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
$(document).ready(function() {
    //find the current font size
    var originalFontSize = $(‘html‘).css(‘font-size‘);
  
    //Increase the text size
    $(".increaseFont").click(function() {
        var currentFontSize = $(‘html‘).css(‘font-size‘);
        var currentFontSizeNumber = parseFloat(currentFontSize, 10);
  
        var newFontSize = currentFontSizeNumber*1.2;
        $(‘html‘).css(‘font-size‘, newFontSize);
        return false;
    });
  
    //Decrease the Text Size
    $(".decreaseFont").click(function() {
        var currentFontSize = $(‘html‘).css(‘font-size‘);
        var currentFontSizeNum = parseFloat(currentFontSize, 10);
  
        var newFontSize = currentFontSizeNum*0.8;
        $(‘html‘).css(‘font-size‘, newFontSize);
        return false;
    });
  
    // Reset Font Size
    $(".resetFont").click(function(){
    $(‘html‘).css(‘font-size‘, originalFontSize);
  });
});

 3、新窗口打开连接

 

1
2
3
4
5
$(document).ready(function() {
    //select all anchor tags that have http in the href
    //and apply the target=_blank
    $("a[href^=‘http‘]").attr(‘target‘,‘_blank‘);
});

 

 4、样式表切换

 

1
2
3
4
5
6
$(document).ready(function() {
    $("a.cssSwap").click(function() {
        //swap the link rel attribute with the value in the rel  
        $(‘link[rel=stylesheet]‘).attr(‘href‘ , $(this).attr(‘rel‘));
    });
});

 

 5、回到顶部

1
2
3
4
5
6
7
$(document).ready(function() {
    //when the id="top" link is clicked
    $(‘#top‘).click(function() {
        //scoll the page back to the top
        $(document).scrollTo(0,500);
    }
});

 6、获取鼠标的 X、Y 坐标

1
2
3
4
$(obj).mousemove(function(e){
    //display the x and y axis values inside the P element
    $(‘p‘).html("X Axis : " + e.pageX + " | Y Axis " + e.pageY);
});

 7、检测当前鼠标的坐标

1
2
3
4
$(document).ready(function() {
    $(obj).mousemove(function(e){
    $(‘# MouseCoordinates ‘).html("X Axis Position = " + e.pageX + " and Y Axis Position = " + e.pageY);
});

 

开发中可能会用到的几个 jQuery 小提示和技巧,布布扣,bubuko.com

开发中可能会用到的几个 jQuery 小提示和技巧

原文:http://www.cnblogs.com/hutuzhu/p/3585889.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!