8个对程序员来说有用的jQuery小贴士和技巧
1) 禁用鼠标右键单击
jQuery程序员可以使用此代码在网页上禁用鼠标右键点击。
|
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) 利用jQuery调整文字大小
使用此代码,用户可以重新网站上文字的大小(增大和减少)
|
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) 在新的Windows打开链接
Try this code and increase your site impressions because using this jquery code users will go on new window after clicking on any link of your site. Code is below: -
|
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) Style Sheets Swap
Swap style sheets using this code and the “Style sheets swap” script is below: -
|
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) 回到顶部链接
That is very common function you can see on eve site nowadays is ” Back to Top”. This functionality is very useful for long pages for make short in a single click. Visit this code below: -
|
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轴
You can find the values of X and Y coordinator of mouse pointer. Code is blow : -
|
1
2
3
4
|
$().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) 检测当前鼠标坐标
使用这个脚本,你可以在jQuery所支持的任何Web浏览器找到当前鼠标的坐标。代码如下:
|
1
2
3
4
5
|
$(document).ready(function() {$().mousemove(function(e){$('# MouseCoordinates ').html("X Axis Position = " + e.pageX + " and Y Axis Position = " + e.pageY);}); |
});
8) 在jQuery中预加载图片
此图像预加载的脚本有助于非常快速加载图像或网页。你不必等待图像加载。代码:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
jQuery.preloadImagesInWebPage = function() { for(var ctr = 0; ctr<arguments.length; ctr++){jQuery("<img alt="">").attr("src", arguments[ctr]);}}To use the above method, you can use the following piece of code:$.preloadImages("image1.gif", "image2.gif", "image3.gif");To check whether an image has been loaded, you can use the following piece of code:$('#imageObject').attr('src', 'image1.gif').load(function() {alert('The image has been loaded…');}); |
8个对程序员来说有用的jQuery小贴士和技巧的更多相关文章
- 30个有关Python的小技巧,给程序员的 30 个基本 Python 贴士与技巧
30个有关Python的小技巧 2013/07/04 · Python, 开发 · 4 评论 · Python 分享到: 66 本文由 伯乐在线 - Kevin Sun 翻译.未经许可,禁止转载!英文 ...
- 一:对程序员来说CPU是什么?
0.开篇 (1)程序是什么? 指示计算机每一步动作的一组指令 (2)程序是由什么组成的? 指令和数据 (3)什么是机器语言? ...
- 【python】对于程序员来说,2018刑侦科推理试卷是问题么?
最近网上很火的2018刑侦科推理试卷,题目确实很考验人逻辑思维能力. 可是对于程序员来说,这根本不是问题.写个程序用穷举法计算一遍即可,太简单. import itertools class Solu ...
- 18个Java8日期处理的实践,对于程序员太有用了!
18个Java8日期处理的实践,对于程序员太有用了! Java 8 推出了全新的日期时间API,在教程中我们将通过一些简单的实例来学习如何使用新API. Java处理日期.日历和时间的方式一直为社区所 ...
- (转)程序员应该知道的10个eclipse调试技巧
调试不仅可以查找到应用程序缺陷所在,还可以解决缺陷.对于Java程序员来说,他们不仅要学会如何在Eclipse里面开发像样的程序,更需要学会如何调试程序.本文介绍了Java程序员必知的10个调试技巧, ...
- Java程序员应该知道的10个Eclipse调试技巧
Eclipse是众多Java程序员实用的开发工具,其中开发技巧也是繁多,但作为优秀的Java程序员,需要掌握最起码的调试技巧. 1 条件断点 2 异常断点 3 监视点 4 评估/检查 5 修改变量值 ...
- 从程序员的角度分析微信小程序(编程语言:用到什么学什么)
从程序员的角度分析微信小程序(编程语言:用到什么学什么) 一.总结 一句话总结:微信小程序原理就是用JS调用底层native组件,和React Native非常类似.(需要时,用到时再学) 1.选择语 ...
- (第一章)对程序员来说CPU是什么
这几天,看到一本书,<程序是怎么跑起来的>,觉得之前都没有完整的看完一本书,现在要从这本书开始,慢慢的培养自己写读书笔记的习惯,不能度过去就忘了. 学习是一个螺旋上升的过程,不要指望一下子 ...
- 《程序是怎样跑起来的》读书笔记——第一章 对程序员来说CPU是什么
1 程序的运行流程 2 CPU的组成 3 寄存器的主要种类和功能 "程序计数器"--决定程序流程的 4 条件分支和循环机制 4.1 顺序执行 4.2 选择分支 5 函数的调用机制 ...
随机推荐
- Ubuntu18.04 之jdk安装与环境配置
1.oracle官网下载压缩包. 下载地址为: https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133 ...
- 洛谷——P2756 飞行员配对方案问题
P2756 飞行员配对方案问题 题目背景 第二次世界大战时期.. 题目描述 英国皇家空军从沦陷国征募了大量外籍飞行员.由皇家空军派出的每一架飞机都需要配备在航行技能和语言上能互相配合的2 名飞行员,其 ...
- TRUNCATE can't with condition
No, TRUNCATE is all or nothing. You can do a DELETE FROM <table> WHERE <conditions> but ...
- [leetcode greedy]134. Gas Station
There are N gas stations along a circular route, where the amount of gas at station i is gas[i]. You ...
- Charles 对于线上比一比抓包怎么修改
1: http://m.1768.com/?act=game_biyibi&abeam=1 Map Local /Users/zhengming/Desktop/biyibi.html biy ...
- 【Codeforces 498B】 B. Name That Tune (概率DP)
B. Name That Tune time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- hihocoder 1526 序列的值
题面在这里! 好久没做题啦,养生一下qwq 推一推贡献就会发现这TM就是一个水题啊! #include<bits/stdc++.h> #define ll long long using ...
- BZOJ 4066 简单题(KD树)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=4066 [题目大意] 要求维护矩阵内格子加点和矩阵查询 [题解] 往KD树上加权值点,支 ...
- [POI2000]Repetitions
题目大意: 求多个字符串的LCS. 思路: 同SPOJ-LCS2,不过因为SPOJ上数据比较水,当时用错误的写法过掉了,这次用正确的写法重新过了一遍. 拓扑排序按照每个状态的len值,用计数排序实现. ...
- 深入理解RESTful Web Services
RESTful的软件架构已经多火不用多说,和MVC架构一样,很多网站服务(Web Services)都遵循RESTful设计模式,那么到底什么是RESTful Web Services呢?设计一个RE ...