推荐10个很棒的jQuery特效代码

推荐10个很棒的jQuery特效代码

2023年7月9日发(作者:)

推荐10个很棒的jQuery特效代码1.图⽚预加载

(function($) { var cache = []; // Arguments are image paths relative to the current page. $.preLoadImages = function() { var args_len = ; for (var i = args_len; i--;) { var cacheImage = Element('img'); = arguments[i]; (cacheImage); } }

dImages("", "/path/to/");2. 在新窗⼝打开链接 (target=”blank”)

$('a[@rel$='external']').click(function(){ = "_blank";});

/* Usage: */3.当⽀持 JavaScript 时为 body 增加 class

/* 该代码只有1⾏,但是最简单的⽤来检测浏览器是否⽀持 JavaScript 的⽅法,如果⽀持 JavaScript 就在 body 元素增加⼀个 hasJS 的 class */$('body').addClass('hasJS');4.平滑滚动页⾯到某个锚点

$(document).ready(function() { $("k").click(function() { $("html, body").animate({ scrollTop: $($(this).attr("href")).offset().top + "px" }, { duration: 500, easing: "swing" }); return false; });});5. ⿏标滑动时的渐⼊和渐出

$(document).ready(function(){ $(".thumbs img").fadeTo("slow", 0.6);

// This sets the opacity of the thumbs to fade down to 60% when the page loads

$(".thumbs img").hover(function(){ $(this).fadeTo("slow", 1.0);

// This should set the opacity to 100% on hover },function(){ $(this).fadeTo("slow", 0.6);

// This should set the opacity back to 60% on mouseout });});6. 制作等⾼的列

var max_height = 0;$("").each(function(){ if ($(this).height() > max_height) { max_height = $(this).height(); }});$("").height(max_height);7. 在⼀些⽼的浏览器上启⽤ HTML5 的⽀持

(function(){ if(!/*@cc_on!@*/0) return; var e = "abbr,article,aside,audio,bb,canvas,datagrid,datalist,details,dialog,eventsource,figure,footer,header,hgroup,mark,menu,meter,nav,output,progress,section,time,video".split(','),i=;while(i--){Element(e[i])}})()

var supports = (function() { var div = Element('div'), vendors = 'Khtml Ms O Moz Webkit'.split(' '), len = ;

return function(prop) { if ( prop in ) return true;

prop = e(/^[a-z]/, function(val) { return rCase(); });

while(len--) { if ( vendors[len] + prop in ) { // browser supports box-shadow. Do what you need. // Or use a bang (!) to test if the browser doesn't. return true; } } return false; };})();

if ( supports('textShadow') ) { ame += ' textShadow';9. 获取 URL 中传递的参数

$.urlParam = function(name){ var results = new RegExp('[?&]' + name + '=([^&#]*)').exec(); if (!results) { return 0; } return results[1] || 0;}10. 禁⽤表单的回车键提交

$("#form").keypress(function(e) { if ( == 13) { return false; }});

发布者:admin,转转请注明出处:http://www.yc00.com/news/1688850597a176552.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信