多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > 互聯網 > 8個超實用的jQuery技巧攻略

8個超實用的jQuery技巧攻略

來源:程序員人生   發布時間:2014-10-19 08:00:00 閱讀次數:3267次

本文我們將為jQuery用戶分享8個超實用的技巧攻略。jQuery是JavaScript最好的庫之一,主要用于制作動畫、事件處理,支持Ajax及HTML 腳本客戶端。此外,jQuery還擁有各種插件,以幫助開發者在最短時間內快速創建網站/網頁。


文中分享的這些實用代碼,希望你會喜歡。

1)禁用右鍵單擊功能

如果你想為用戶節省網站信息,那么開發者可以使用這段代碼――禁用右鍵單擊功能。

code_snippet_id="214791" snippet_file_name="ptcms_1393830498_0.js"><font><font>$(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; }); });</font></font>

2)使用jQuery設定文本大小

使用這段代碼,用戶可根據需求重新設定文本尺寸(增加或減少)。

code_snippet_id="214791" snippet_file_name="ptcms_1393830498_1.js"><font><font>$(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); }); });</font></font>

3)在新窗口打開鏈接 

使用這段代碼會幫助用戶在新窗口打開鏈接,為用戶帶來更好的用戶體驗。 

code_snippet_id="214791" snippet_file_name="ptcms_1393830498_2.js">$(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)更改樣式列表

使用這段代碼幫助你更改樣式列表。 

$(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)返回到頂部鏈接

此代碼對于長時間點擊單頁面非常實用,你可以在重要關頭點擊“返回頂部”功能。 

code_snippet_id="214791" snippet_file_name="ptcms_1393830498_3.js">$(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軸

code_snippet_id="214791" snippet_file_name="ptcms_1393830498_4.js"><font><font>$().mousemove(function(e){ //display the x and y axis values inside the P element $('p').html("X Axis : " + e.pageX + " | Y Axis " + e.pageY); });</font></font>
7)檢測當前鼠標坐標 

使用這個腳本,你可以在任何網絡瀏覽器獲取鼠標坐標。 

code_snippet_id="214791" snippet_file_name="ptcms_1393830498_5.js">$(document).ready(function() { $().mousemove(function(e) { $('# MouseCoordinates ').html("X Axis Position = " + e.pageX + " and Y Axis Position = " + e.pageY); });

8)圖片預加載

此段代碼幫助用戶快速加載圖片或網頁頁面。

code_snippet_id="214791" snippet_file_name="ptcms_1393830498_6.js"><font><font>jQuery.preloadImagesInWebPage = function() { for(var ctr = 0; ctr<arguments.length; ctr++) { jQuery("").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…'); });</font></font>

原文出自: Designzum

生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
為碼而活
積分:4237
15粉絲
7關注
欄目熱點
關閉
程序員人生
主站蜘蛛池模板: 欧美亚洲精品一区 | 久久一区二区三区99 | 精品一区二区三区高清免费不卡 | 免费在线播放毛片 | 男女免费爽爽爽在线视频 | 国产精品久久久久久久久久久久 | 欧美国产日韩久久久 | 一区二区高清视频 | 一区二区三区高清在线观看 | 国产伦精品一区二区三区在线观看 | 伊人五月天综合 | 亚洲视频2 | 最新亚洲国产有精品 | 日韩欧美久久一区二区 | 国产成人a v在线影院 | 青青国产成人精品视频 | 欧美free性俄罗斯xxx | 老司机福利免费 | 亚洲一区二区三区免费 | 伊人久久精品 | 欧美老女人性视频 | 欧美91精品久久久久网免费 | 樱花aⅴ一区二区三区四区 影视精品网站入口 | 国内交换一区二区三区 | 国内精品免费一区二区三区 | 亚洲韩国日本欧美一区二区三区 | 亚洲国产精品尤物yw在线观看 | 欧美成人看片一区二区三区 | 我爱我色成人网 | 亚洲欧洲精品成人久久曰 | 久久精品一区二区三区日韩 | 欧美天堂视频 | 欧美三级真做在线观看 | 老黄网站在线观看免费 | 日本高清www午夜视频 | 国产精品一国产精品免费 | a天堂在线| 国产成人精品日本亚洲专区6 | 国产中文字幕在线视频 | 亚洲国产一区二区三区精品 | 日本不卡视频在线 |