jQuery User Manual 3 CSS Operation_jquery
传统javascript对css的操作相当繁琐,比如
$("#a")得到jQuery对象[
$("#a").background()将取出该对象的background样式。
$("#a").background(“red”)将该对象的background样式设为redjQuery提供了以下方法,来操作css
background () background (val) color() color(val) css(name) css(prop)
css(key, value) float() float(val) height() height(val) width() width(val)
left() left(val) overflow() overflow(val) position() position(val) top() top(val)
这里需要讲解一下css(name) css(prop) css(key, value),其他的看名字都知道什么作用了!
css(name) 获取样式名为name的样式
$("#a").css("color") 将得到样式中color值red,("#a").css("background ")将得到blue
css(prop) prop是一个hash对象,用于设置大量的css样式
$("#b").css({ color: "red", background: "blue" });
最终效果是
test
,{ color: "red", background: "blue" },hash对象,color为key,"red"为value,css(key, value) 用于设置一个单独得css样式
$("#b").css("color","red");最终效果是
test
四:JavaScript处理
$.browser() 判断浏览器类型,返回boolen值
if($.browser.msie) {
alert("这是一个IE浏览器");}
else if($.browser.opera) {
alert("这是一个opera浏览器");}
})
$.each(obj, fn) obj为对象或数组,fn为在obj上依次执行的函数,注意区分$().each()
$.extend(obj, prop) 用第二个对象扩展第一个对象
var options = { validate: true, name: "bar" };
$.extend(settings, options);
可以用下面函数来测试
var settings = { validate: false, limit: 5, name: "foo" };
var options = { validate: true, name: "bar" };
$.extend(settings, options);
$.each(settings, function(i){ alert( i + "=" + this ); });
})
$.grep(array,fn) 通过函数fn来过滤array,将array中的元素依次传给fn,fn必须返回一个boolen,如fn返回true,将被过滤
var arr= $.grep( [0,1,2,3,4], function(i){ return i > 2; });
$.each(arr, function(i){ alert(i); });
})
$.merge(first, second) 两个参数都是数组,排出第二个数组中与第一个相同的,再将两个数组合并
var arr = $.merge( [0,1,2], [2,3,4] )
$.each(arr, function(i){ alert(i); });
})
$.trim(str) 移出字符串两端的空格
$.trim(" hello, how are you? ")的结果是"hello, how are you?"
五:动态效果
在将这部分之前我们先看个例子,相信做网页的朋友都遇到n级菜单的情景,但点击某菜单按钮时,如果它的子菜单是显示的,则隐藏子菜单,如果子菜单隐藏,则显示出来,传统的javascript做法是先用getElementById取出子菜单所在容器的id,在判断该容器的style.display是否等于none,如果等于则设为block,如果不等于这设为none,如果在将效果设置复杂一点,当点击按钮时,不是忽然隐藏和显示子菜单,而是高度平滑的转变,这时就要通过setTimeout来设置子菜单的height了,再复杂一点透明度也平滑的消失和显现,这时显现下来需要编写很多代码,如果js基础不好的朋友可能只能从别人写好的代码拿过来修改了!jQuery实现上面效果只需要1句话就行,$("#a").toggle("slow"),,学完jQuery后还需要抄袭修改别人的代码吗?下面我们逐个介绍jQuery用于效果处理的方法。
hide() 隐藏匹配对象
show() 显示匹配对象
hide(speed) 以一定的速度隐藏匹配对象,其大小(长宽)和透明度都逐渐变化到0,speed有3级("slow", "normal", "fast"),也可以是自定义的速度。
show(speed) 以一定的速度显示匹配对象,其大小(长宽)和透明度都由0逐渐变化到正常
hide(speed, callback) show(speed, callback) 当显示和隐藏变化结束后执行函数callback
toggle() toggle(speed) 如果当前匹配对象隐藏,则显示他们,如果当前是显示的,就隐藏,toggle(speed),其大小(长宽)和透明度都随之逐渐变化。


fadeIn(speeds) fadeOut(speeds) 根据速度调整透明度来显示或隐藏匹配对象,注意有别于hide(speed)和show(speed),fadeIn和fadeOut都只调整透明度,不调整大小
fadeIn(speed, callback) fadeOut(speed, callback) callback is a function, first display or hide the matching object by adjusting the transparency, and execute the callback function after the adjustment is completed
<a href="#" onClick='$ ("img ").fadeIn("slow",function(){ alert("Animation Done."); })'> jQuery a>
fadeTo(speed, opacity, callback) Adjust the opacity of the matching object at speed, and then execute the function callback. Opacity is the final transparency (0-1).
<a href="# " onClick='$("img ").fadeTo("slow",0.55,function(){ alert("Animation Done."); })'> jQuery a>
slideDown(speeds) Smoothly change the height of the matching object from 0 to normal at the specified rate!
<a href= "#" onClick='$("img ").slideDown("slow")'>jQuerya>
slideDown(speeds,callback) Change the height of the matching object from 0 to normal! After the change is completed, execute the function callback
slideUp("slow") slideUp(speed, callback) The height of the matching object changes from normal to 0
slideToggle("slow") If the height of the matching object is normal, it will gradually change to 0. If it is 0, it will gradually change to normal

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Frequently Asked Questions and Solutions for Front-end Thermal Paper Ticket Printing In Front-end Development, Ticket Printing is a common requirement. However, many developers are implementing...

There is no absolute salary for Python and JavaScript developers, depending on skills and industry needs. 1. Python may be paid more in data science and machine learning. 2. JavaScript has great demand in front-end and full-stack development, and its salary is also considerable. 3. Influencing factors include experience, geographical location, company size and specific skills.

JavaScript is the cornerstone of modern web development, and its main functions include event-driven programming, dynamic content generation and asynchronous programming. 1) Event-driven programming allows web pages to change dynamically according to user operations. 2) Dynamic content generation allows page content to be adjusted according to conditions. 3) Asynchronous programming ensures that the user interface is not blocked. JavaScript is widely used in web interaction, single-page application and server-side development, greatly improving the flexibility of user experience and cross-platform development.

How to merge array elements with the same ID into one object in JavaScript? When processing data, we often encounter the need to have the same ID...

Discussion on the realization of parallax scrolling and element animation effects in this article will explore how to achieve similar to Shiseido official website (https://www.shiseido.co.jp/sb/wonderland/)...

In-depth discussion of the root causes of the difference in console.log output. This article will analyze the differences in the output results of console.log function in a piece of code and explain the reasons behind it. �...

Learning JavaScript is not difficult, but it is challenging. 1) Understand basic concepts such as variables, data types, functions, etc. 2) Master asynchronous programming and implement it through event loops. 3) Use DOM operations and Promise to handle asynchronous requests. 4) Avoid common mistakes and use debugging techniques. 5) Optimize performance and follow best practices.

Explore the implementation of panel drag and drop adjustment function similar to VSCode in the front-end. In front-end development, how to implement VSCode similar to VSCode...
